mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	js: Convert static/js/color_data.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							6f660793e7
						
					
				
				
					commit
					374dfc2fda
				
			@@ -135,7 +135,6 @@
 | 
			
		||||
                "buddy_data": false,
 | 
			
		||||
                "buddy_list": false,
 | 
			
		||||
                "click_handlers": false,
 | 
			
		||||
                "color_data": false,
 | 
			
		||||
                "compose_actions": false,
 | 
			
		||||
                "compose_ui": false,
 | 
			
		||||
                "composebox_typeahead": false,
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,7 @@ const {run_test} = require("../zjsunit/test");
 | 
			
		||||
const color_data = zrequire("color_data");
 | 
			
		||||
 | 
			
		||||
run_test("pick_color", () => {
 | 
			
		||||
    color_data.colors = ["blue", "orange", "red", "yellow"];
 | 
			
		||||
    color_data.__Rewire__("colors", ["blue", "orange", "red", "yellow"]);
 | 
			
		||||
 | 
			
		||||
    color_data.reset();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -653,7 +653,7 @@ run_test("create_sub", () => {
 | 
			
		||||
        color: "#76ce90",
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    color_data.pick_color = () => "#bd86e5";
 | 
			
		||||
    color_data.__Rewire__("pick_color", () => "#bd86e5");
 | 
			
		||||
 | 
			
		||||
    const india_sub = stream_data.create_sub_from_server_data(india);
 | 
			
		||||
    assert(india_sub);
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,8 @@
 | 
			
		||||
 | 
			
		||||
const {strict: assert} = require("assert");
 | 
			
		||||
 | 
			
		||||
const rewiremock = require("rewiremock/node");
 | 
			
		||||
 | 
			
		||||
const {set_global, zrequire} = require("../zjsunit/namespace");
 | 
			
		||||
const {make_stub} = require("../zjsunit/stub");
 | 
			
		||||
const {run_test} = require("../zjsunit/test");
 | 
			
		||||
@@ -13,7 +15,8 @@ const _settings_notifications = {
 | 
			
		||||
};
 | 
			
		||||
set_global("settings_notifications", _settings_notifications);
 | 
			
		||||
 | 
			
		||||
const color_data = set_global("color_data", {});
 | 
			
		||||
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", {});
 | 
			
		||||
@@ -35,6 +38,8 @@ set_global("message_list", {
 | 
			
		||||
subs = set_global("subs", {update_settings_for_subscribed: noop});
 | 
			
		||||
set_global("overlays", {streams_open: () => true});
 | 
			
		||||
 | 
			
		||||
rewiremock.enable();
 | 
			
		||||
 | 
			
		||||
const peer_data = zrequire("peer_data");
 | 
			
		||||
const people = zrequire("people");
 | 
			
		||||
const stream_data = zrequire("stream_data");
 | 
			
		||||
@@ -397,3 +402,4 @@ run_test("remove_deactivated_user_from_all_streams", () => {
 | 
			
		||||
    // verify that we issue a call to update subscriber count/list UI
 | 
			
		||||
    assert.equal(subs_stub.num_calls, 1);
 | 
			
		||||
});
 | 
			
		||||
rewiremock.disable();
 | 
			
		||||
 
 | 
			
		||||
@@ -110,7 +110,6 @@ const util = zrequire("util");
 | 
			
		||||
zrequire("hash_util");
 | 
			
		||||
zrequire("stream_color");
 | 
			
		||||
zrequire("stream_edit");
 | 
			
		||||
zrequire("color_data");
 | 
			
		||||
zrequire("stream_data");
 | 
			
		||||
zrequire("condense");
 | 
			
		||||
zrequire("lightbox");
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,8 @@ import _ from "lodash";
 | 
			
		||||
 | 
			
		||||
import render_archive_message_group from "../templates/archive_message_group.hbs";
 | 
			
		||||
 | 
			
		||||
import * as color_data from "./color_data";
 | 
			
		||||
 | 
			
		||||
const {format, isSameDay} = require("date-fns");
 | 
			
		||||
 | 
			
		||||
function should_separate_into_groups(current_msg_time, next_msg_time) {
 | 
			
		||||
 
 | 
			
		||||
@@ -25,7 +25,6 @@ import "../message_list";
 | 
			
		||||
import "../narrow";
 | 
			
		||||
import "../reload";
 | 
			
		||||
import "../compose_actions";
 | 
			
		||||
import "../color_data";
 | 
			
		||||
import "../stream_color";
 | 
			
		||||
import "../stream_data";
 | 
			
		||||
import "../stream_topic_history";
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
"use strict";
 | 
			
		||||
import _ from "lodash";
 | 
			
		||||
 | 
			
		||||
const _ = require("lodash");
 | 
			
		||||
export let unused_colors;
 | 
			
		||||
// These colors are used now for streams.
 | 
			
		||||
const stream_colors = [
 | 
			
		||||
    "#76ce90",
 | 
			
		||||
@@ -31,41 +31,39 @@ const stream_colors = [
 | 
			
		||||
 | 
			
		||||
// Shuffle our colors on page load to prevent
 | 
			
		||||
// bias toward "early" colors.
 | 
			
		||||
exports.colors = _.shuffle(stream_colors);
 | 
			
		||||
export const colors = _.shuffle(stream_colors);
 | 
			
		||||
 | 
			
		||||
exports.reset = function () {
 | 
			
		||||
    exports.unused_colors = exports.colors.slice();
 | 
			
		||||
};
 | 
			
		||||
export function reset() {
 | 
			
		||||
    unused_colors = colors.slice();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.reset();
 | 
			
		||||
reset();
 | 
			
		||||
 | 
			
		||||
exports.claim_color = function (color) {
 | 
			
		||||
    const i = exports.unused_colors.indexOf(color);
 | 
			
		||||
export function claim_color(color) {
 | 
			
		||||
    const i = unused_colors.indexOf(color);
 | 
			
		||||
 | 
			
		||||
    if (i < 0) {
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    exports.unused_colors.splice(i, 1);
 | 
			
		||||
    unused_colors.splice(i, 1);
 | 
			
		||||
 | 
			
		||||
    if (exports.unused_colors.length === 0) {
 | 
			
		||||
        exports.reset();
 | 
			
		||||
    if (unused_colors.length === 0) {
 | 
			
		||||
        reset();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.claim_colors = function (subs) {
 | 
			
		||||
export function claim_colors(subs) {
 | 
			
		||||
    const colors = new Set(subs.map((sub) => sub.color));
 | 
			
		||||
    for (const color of colors) {
 | 
			
		||||
        exports.claim_color(color);
 | 
			
		||||
        claim_color(color);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.pick_color = function () {
 | 
			
		||||
    const color = exports.unused_colors[0];
 | 
			
		||||
export function pick_color() {
 | 
			
		||||
    const color = unused_colors[0];
 | 
			
		||||
 | 
			
		||||
    exports.claim_color(color);
 | 
			
		||||
    claim_color(color);
 | 
			
		||||
 | 
			
		||||
    return color;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
window.color_data = exports;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1
									
								
								static/js/global.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								static/js/global.d.ts
									
									
									
									
										vendored
									
									
								
							@@ -13,7 +13,6 @@ declare let bot_data: any;
 | 
			
		||||
declare let buddy_data: any;
 | 
			
		||||
declare let buddy_list: any;
 | 
			
		||||
declare let click_handlers: any;
 | 
			
		||||
declare let color_data: any;
 | 
			
		||||
declare let compose_actions: any;
 | 
			
		||||
declare let composebox_typeahead: any;
 | 
			
		||||
declare let compose_ui: any;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
"use strict";
 | 
			
		||||
 | 
			
		||||
const color_data = require("./color_data");
 | 
			
		||||
const {FoldDict} = require("./fold_dict");
 | 
			
		||||
const peer_data = require("./peer_data");
 | 
			
		||||
const people = require("./people");
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
"use strict";
 | 
			
		||||
 | 
			
		||||
const color_data = require("./color_data");
 | 
			
		||||
const narrow_state = require("./narrow_state");
 | 
			
		||||
const peer_data = require("./peer_data");
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user