Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

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

Anders Kaseorgd81ba3698fdc
diff --git a/.eslintrc.json b/.eslintrc.json
index 2353192134a..23d89c649ae 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -212,7 +212,6 @@
"settings_user_groups": false,
"settings_users": false,
"starred_messages": false,
- "stream_color": false,
"stream_data": false,
"stream_edit": false,
"stream_events": false,
diff --git a/frontend_tests/node_tests/drafts.js b/frontend_tests/node_tests/drafts.js
index a4e04a2a11d..47ec968bb04 100644
--- a/frontend_tests/node_tests/drafts.js
+++ b/frontend_tests/node_tests/drafts.js
@@ -46,7 +46,6 @@ rewiremock.enable();
const {localstorage} = zrequire("localstorage");
const drafts = zrequire("drafts");
const timerender = zrequire("timerender");
-zrequire("stream_color");
const legacy_draft = {
stream: "stream",
diff --git a/frontend_tests/node_tests/stream_edit.js b/frontend_tests/node_tests/stream_edit.js
index 5c52a8bccd6..2774786de05 100644
--- a/frontend_tests/node_tests/stream_edit.js
+++ b/frontend_tests/node_tests/stream_edit.js
@@ -25,7 +25,7 @@ const page_params = set_global("page_params", {});
set_global("settings_notifications", {
get_notifications_table_row_data: noop,
});
-set_global("stream_color", {
+rewiremock("../../static/js/stream_color").with({
set_colorpicker_color: noop,
});
const typeahead_helper = set_global("typeahead_helper", {});
diff --git a/frontend_tests/node_tests/stream_events.js b/frontend_tests/node_tests/stream_events.js
index 11049f676c1..cd883090001 100644
--- a/frontend_tests/node_tests/stream_events.js
+++ b/frontend_tests/node_tests/stream_events.js
@@ -19,7 +19,8 @@ const color_data = {__esModule: true};
rewiremock("../../static/js/color_data").with(color_data);
set_global("current_msg_list", {});
const message_util = set_global("message_util", {});
-const stream_color = set_global("stream_color", {});
+const stream_color = {__esModule: true};
+rewiremock("../../static/js/stream_color").with(stream_color);
const stream_list = set_global("stream_list", {});
const stream_muting = set_global("stream_muting", {});
let subs = set_global("subs", {});
diff --git a/frontend_tests/node_tests/ui_init.js b/frontend_tests/node_tests/ui_init.js
index ebea603c7dc..80c5df800d4 100644
--- a/frontend_tests/node_tests/ui_init.js
+++ b/frontend_tests/node_tests/ui_init.js
@@ -108,7 +108,6 @@ rewiremock.enable();
const util = zrequire("util");
zrequire("hash_util");
-zrequire("stream_color");
zrequire("stream_edit");
zrequire("stream_data");
zrequire("condense");
diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js
index 9fceb292c02..341e4099c51 100644
--- a/static/js/bundles/app.js
+++ b/static/js/bundles/app.js
@@ -25,7 +25,6 @@ import "../message_list";
import "../narrow";
import "../reload";
import "../compose_actions";
-import "../stream_color";
import "../stream_data";
import "../stream_topic_history";
import "../stream_muting";
diff --git a/static/js/drafts.js b/static/js/drafts.js
index dae129cded4..ee5d594123d 100644
--- a/static/js/drafts.js
+++ b/static/js/drafts.js
@@ -9,6 +9,7 @@ import * as compose_state from "./compose_state";
import {localstorage} from "./localstorage";
import * as markdown from "./markdown";
import * as people from "./people";
+import * as stream_color from "./stream_color";
import * as util from "./util";
function set_count(count) {
diff --git a/static/js/global.d.ts b/static/js/global.d.ts
index 5254c149423..c5ba3b69570 100644
--- a/static/js/global.d.ts
+++ b/static/js/global.d.ts
@@ -85,7 +85,6 @@ declare let settings_toggle: any;
declare let settings_user_groups: any;
declare let settings_users: any;
declare let starred_messages: any;
-declare let stream_color: any;
declare let stream_data: any;
declare let stream_edit: any;
declare let stream_events: any;
diff --git a/static/js/message_list_view.js b/static/js/message_list_view.js
index bb7ca0062b3..7fbf0e54942 100644
--- a/static/js/message_list_view.js
+++ b/static/js/message_list_view.js
@@ -13,6 +13,7 @@ import * as narrow_state from "./narrow_state";
import * as people from "./people";
import * as rendered_markdown from "./rendered_markdown";
import * as rows from "./rows";
+import * as stream_color from "./stream_color";
import * as submessage from "./submessage";
import * as util from "./util";
diff --git a/static/js/stream_color.js b/static/js/stream_color.js
index 309fea874c1..0d4498d8a3b 100644
--- a/static/js/stream_color.js
+++ b/static/js/stream_color.js
@@ -1,16 +1,15 @@
-"use strict";
+import _ from "lodash";
-const _ = require("lodash");
+import * as colorspace from "./colorspace";
-const colorspace = require("./colorspace");
-
-exports.default_color = "#c2c2c2";
+export const default_color = "#c2c2c2";
// Classes which could be returned by get_color_class.
-exports.color_classes = "dark_background";
+export const color_classes = "dark_background";
let lightness_threshold;
-exports.initialize = function () {
+
+export function initialize() {
// sRGB color component for dark label text.
// 0x33 to match the color #333333 set by Bootstrap.
const label_color = 0x33;
@@ -18,7 +17,7 @@ exports.initialize = function () {
// Compute midpoint lightness between that and white (100).
lightness_threshold = (lightness + 100) / 2;
-};
+}
// From a background color (in format "#fff" or "#ffffff")
// pick a CSS class (or empty string) to determine the
@@ -29,7 +28,7 @@ exports.initialize = function () {
// already saved on the server, etc.
//
// This gets called on every message, so cache the results.
-exports.get_color_class = _.memoize((color) => {
+export const get_color_class = _.memoize((color) => {
let match;
let i;
const channel = [0, 0, 0];
@@ -66,7 +65,7 @@ function update_table_stream_color(table, stream_name, color) {
// This is ugly, but temporary, as the new design will make it
// so that we only have color in the headers.
const style = color;
- const color_class = exports.get_color_class(color);
+ const color_class = get_color_class(color);
const stream_labels = $("#floating_recipient_bar").add(table).find(".stream_label");
@@ -87,7 +86,7 @@ function update_table_stream_color(table, stream_name, color) {
"inset 2px 0px 0px 0px " + style + ", -1px 0px 0px 0px " + style,
);
$label.css({background: style, "border-left-color": style});
- $label.removeClass(exports.color_classes);
+ $label.removeClass(color_classes);
$label.addClass(color_class);
}
}
@@ -119,15 +118,15 @@ const subscriptions_table_colorpicker_options = {
palette: stream_color_palette,
};
-exports.set_colorpicker_color = function (colorpicker, color) {
+export function set_colorpicker_color(colorpicker, color) {
colorpicker.spectrum({
...subscriptions_table_colorpicker_options,
color,
container: "#subscription_overlay .subscription_settings.show",
});
-};
+}
-exports.update_stream_color = function (sub, color, opts) {
+export function update_stream_color(sub, color, opts) {
opts = {update_historical: false, ...opts};
sub.color = color;
const stream_id = sub.stream_id;
@@ -137,7 +136,7 @@ exports.update_stream_color = function (sub, color, opts) {
color,
);
// The swatch in the color picker.
- exports.set_colorpicker_color(
+ set_colorpicker_color(
$(
`#subscription_overlay .subscription_settings[data-stream-id='${CSS.escape(
stream_id,
@@ -156,7 +155,7 @@ exports.update_stream_color = function (sub, color, opts) {
}
update_stream_sidebar_swatch_color(stream_id, color);
message_view_header.colorize_message_view_header();
-};
+}
function picker_do_change_color(color) {
const stream_id = Number.parseInt($(this).attr("stream_id"), 10);
@@ -165,7 +164,7 @@ function picker_do_change_color(color) {
}
subscriptions_table_colorpicker_options.change = picker_do_change_color;
-exports.sidebar_popover_colorpicker_options = {
+export const sidebar_popover_colorpicker_options = {
clickoutFiresChange: true,
showPaletteOnly: true,
showPalette: true,
@@ -175,7 +174,7 @@ exports.sidebar_popover_colorpicker_options = {
change: picker_do_change_color,
};
-exports.sidebar_popover_colorpicker_options_full = {
+export const sidebar_popover_colorpicker_options_full = {
clickoutFiresChange: false,
showPalette: true,
showInput: true,
@@ -185,5 +184,3 @@ exports.sidebar_popover_colorpicker_options_full = {
palette: stream_color_palette,
change: picker_do_change_color,
};
-
-window.stream_color = exports;
diff --git a/static/js/stream_data.js b/static/js/stream_data.js
index a742f5ccb6c..f2fd21b6b38 100644
--- a/static/js/stream_data.js
+++ b/static/js/stream_data.js
@@ -5,6 +5,7 @@ const {FoldDict} = require("./fold_dict");
const peer_data = require("./peer_data");
const people = require("./people");
const settings_config = require("./settings_config");
+const stream_color = require("./stream_color");
const util = require("./util");
// Expose get_subscriber_count for our automated puppeteer tests.
diff --git a/static/js/stream_edit.js b/static/js/stream_edit.js
index e773293ab6d..d887a6cc931 100644
--- a/static/js/stream_edit.js
+++ b/static/js/stream_edit.js
@@ -14,6 +14,7 @@ const pill_typeahead = require("./pill_typeahead");
const settings_config = require("./settings_config");
const settings_data = require("./settings_data");
const settings_ui = require("./settings_ui");
+const stream_color = require("./stream_color");
const stream_pill = require("./stream_pill");
const stream_ui_updates = require("./stream_ui_updates");
const user_pill = require("./user_pill");
diff --git a/static/js/stream_events.js b/static/js/stream_events.js
index 0880f9d6bad..91aac67b3f1 100644
--- a/static/js/stream_events.js
+++ b/static/js/stream_events.js
@@ -3,6 +3,7 @@
const color_data = require("./color_data");
const narrow_state = require("./narrow_state");
const peer_data = require("./peer_data");
+const stream_color = require("./stream_color");
// In theory, this function should apply the account-level defaults,
// however, they are only called after a manual override, so
diff --git a/static/js/stream_list.js b/static/js/stream_list.js
index 8372f382eb2..78ed07848a6 100644
--- a/static/js/stream_list.js
+++ b/static/js/stream_list.js
@@ -9,6 +9,7 @@ const keydown_util = require("./keydown_util");
const {ListCursor} = require("./list_cursor");
const narrow_state = require("./narrow_state");
const scroll_util = require("./scroll_util");
+const stream_color = require("./stream_color");
const stream_sort = require("./stream_sort");
const topic_list = require("./topic_list");
const topic_zoom = require("./topic_zoom");
diff --git a/static/js/stream_popover.js b/static/js/stream_popover.js
index 849c6208963..9858dbb6006 100644
--- a/static/js/stream_popover.js
+++ b/static/js/stream_popover.js
@@ -11,6 +11,7 @@ const render_unstar_messages_modal = require("../templates/unstar_messages_modal
const channel = require("./channel");
const muting = require("./muting");
const muting_ui = require("./muting_ui");
+const stream_color = require("./stream_color");
// We handle stream popovers and topic popovers in this
// module. Both are popped up from the left sidebar.
diff --git a/static/js/ui_init.js b/static/js/ui_init.js
index a83b36e8fdc..96822cd8dba 100644
--- a/static/js/ui_init.js
+++ b/static/js/ui_init.js
@@ -27,6 +27,7 @@ const reload = require("./reload");
const rows = require("./rows");
const sent_messages = require("./sent_messages");
const spoilers = require("./spoilers");
+const stream_color = require("./stream_color");
const topic_list = require("./topic_list");
const topic_zoom = require("./topic_zoom");
const tutorial = require("./tutorial");
diff --git a/static/js/ui_util.js b/static/js/ui_util.js
index 784d5a6410c..82226520bc4 100644
--- a/static/js/ui_util.js
+++ b/static/js/ui_util.js
@@ -1,5 +1,7 @@
"use strict";
+const stream_color = require("./stream_color");
+
// Add functions to this that have no non-trivial
// dependencies other than jQuery.