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

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-02-10 07:47:46 -08:00 committed by Tim Abbott
parent a17ce6aeee
commit 3b49cf6f24
6 changed files with 19 additions and 24 deletions

View File

@ -271,7 +271,6 @@
"stream_topic_history": false, "stream_topic_history": false,
"stream_list": false, "stream_list": false,
"stream_muting": false, "stream_muting": false,
"stream_pill": false,
"stream_popover": false, "stream_popover": false,
"stream_sort": false, "stream_sort": false,
"stream_ui_updates": false, "stream_ui_updates": false,

View File

@ -24,7 +24,6 @@ import "../localstorage";
import "../drafts"; import "../drafts";
import "../input_pill"; import "../input_pill";
import "../user_pill"; import "../user_pill";
import "../stream_pill";
import "../compose_pm_pill"; import "../compose_pm_pill";
import "../channel"; import "../channel";
import "../setup"; import "../setup";

View File

@ -137,7 +137,6 @@ declare let stream_edit: any;
declare let stream_events: any; declare let stream_events: any;
declare let stream_list: any; declare let stream_list: any;
declare let stream_muting: any; declare let stream_muting: any;
declare let stream_pill: any;
declare let stream_popover: any; declare let stream_popover: any;
declare let stream_sort: any; declare let stream_sort: any;
declare let stream_ui_updates: any; declare let stream_ui_updates: any;

View File

@ -2,6 +2,7 @@
const people = require("./people"); const people = require("./people");
const settings_data = require("./settings_data"); const settings_data = require("./settings_data");
const stream_pill = require("./stream_pill");
exports.set_up = function (input, pills, opts) { exports.set_up = function (input, pills, opts) {
let source = opts.source; let source = opts.source;

View File

@ -10,6 +10,7 @@ const peer_data = require("./peer_data");
const people = require("./people"); const people = require("./people");
const settings_config = require("./settings_config"); const settings_config = require("./settings_config");
const settings_data = require("./settings_data"); const settings_data = require("./settings_data");
const stream_pill = require("./stream_pill");
const util = require("./util"); const util = require("./util");
function setup_subscriptions_stream_hash(sub) { function setup_subscriptions_stream_hash(sub) {

View File

@ -1,13 +1,11 @@
"use strict"; import * as peer_data from "./peer_data";
const peer_data = require("./peer_data");
function display_pill(sub) { function display_pill(sub) {
const sub_count = peer_data.get_subscriber_count(sub.stream_id); const sub_count = peer_data.get_subscriber_count(sub.stream_id);
return "#" + sub.name + ": " + sub_count + " users"; return "#" + sub.name + ": " + sub_count + " users";
} }
exports.create_item_from_stream_name = function (stream_name, current_items) { export function create_item_from_stream_name(stream_name, current_items) {
stream_name = stream_name.trim(); stream_name = stream_name.trim();
if (!stream_name.startsWith("#")) { if (!stream_name.startsWith("#")) {
return undefined; return undefined;
@ -31,11 +29,11 @@ exports.create_item_from_stream_name = function (stream_name, current_items) {
}; };
return item; return item;
}; }
exports.get_stream_name_from_item = function (item) { export function get_stream_name_from_item(item) {
return item.stream_name; return item.stream_name;
}; }
function get_user_ids_from_subs(items) { function get_user_ids_from_subs(items) {
let user_ids = []; let user_ids = [];
@ -48,41 +46,39 @@ function get_user_ids_from_subs(items) {
return user_ids; return user_ids;
} }
exports.get_user_ids = function (pill_widget) { export function get_user_ids(pill_widget) {
const items = pill_widget.items(); const items = pill_widget.items();
let user_ids = get_user_ids_from_subs(items); let user_ids = get_user_ids_from_subs(items);
user_ids = Array.from(new Set(user_ids)); user_ids = Array.from(new Set(user_ids));
user_ids = user_ids.filter(Boolean); user_ids = user_ids.filter(Boolean);
return user_ids; return user_ids;
}; }
exports.append_stream = function (stream, pill_widget) { export function append_stream(stream, pill_widget) {
pill_widget.appendValidatedData({ pill_widget.appendValidatedData({
display_value: display_pill(stream), display_value: display_pill(stream),
stream_id: stream.stream_id, stream_id: stream.stream_id,
stream_name: stream.name, stream_name: stream.name,
}); });
pill_widget.clear_text(); pill_widget.clear_text();
}; }
exports.get_stream_ids = function (pill_widget) { export function get_stream_ids(pill_widget) {
const items = pill_widget.items(); const items = pill_widget.items();
let stream_ids = items.map((item) => item.stream_id); let stream_ids = items.map((item) => item.stream_id);
stream_ids = stream_ids.filter(Boolean); stream_ids = stream_ids.filter(Boolean);
return stream_ids; return stream_ids;
}; }
exports.filter_taken_streams = function (items, pill_widget) { export function filter_taken_streams(items, pill_widget) {
const taken_stream_ids = exports.get_stream_ids(pill_widget); const taken_stream_ids = get_stream_ids(pill_widget);
items = items.filter((item) => !taken_stream_ids.includes(item.stream_id)); items = items.filter((item) => !taken_stream_ids.includes(item.stream_id));
return items; return items;
}; }
exports.typeahead_source = function (pill_widget) { export function typeahead_source(pill_widget) {
const potential_streams = stream_data.get_unsorted_subs(); const potential_streams = stream_data.get_unsorted_subs();
return exports.filter_taken_streams(potential_streams, pill_widget); return filter_taken_streams(potential_streams, pill_widget);
}; }
window.stream_pill = exports;