Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
ts: Convert `emojisets` to TypeScript.
Lalit7346ce98f3c0
diff --git a/tools/test-js-with-node b/tools/test-js-with-nodeindex 96085b18f06..a7e45e8125a 100755--- a/tools/test-js-with-node+++ b/tools/test-js-with-node@@ -86,7 +86,7 @@ EXEMPT_FILES = make_set("web/src/dropdown_widget.js","web/src/echo.js","web/src/emoji_picker.js",- "web/src/emojisets.js",+ "web/src/emojisets.ts","web/src/favicon.ts","web/src/feedback_widget.ts","web/src/flatpickr.js",diff --git a/web/src/assets.d.ts b/web/src/assets.d.tsindex 4795ce2a647..53b34255fea 100644--- a/web/src/assets.d.ts+++ b/web/src/assets.d.ts@@ -7,3 +7,15 @@ declare module "*.ttf" {const url: string;export default url;}++declare module "*.png" {+ const url: string;+ export default url;+}++// Declare the style loader for CSS files. This is used in the+// `import` statements in the `emojisets.ts` file.+declare module "!style-loader?*" {+ const css: {use: () => void; unuse: () => void};+ export default css;+}diff --git a/web/src/emojisets.js b/web/src/emojisets.tssimilarity index 82%rename from web/src/emojisets.jsrename to web/src/emojisets.tsindex ca4dd6dcdc0..5ce0d4f1d11 100644--- a/web/src/emojisets.js+++ b/web/src/emojisets.ts@@ -10,7 +10,12 @@ import google_blob_css from "!style-loader?injectType=lazyStyleTag!css-loader!..import google_css from "!style-loader?injectType=lazyStyleTag!css-loader!../generated/emoji-styles/google-sprite.css";import twitter_css from "!style-loader?injectType=lazyStyleTag!css-loader!../generated/emoji-styles/twitter-sprite.css";-const emojisets = new Map([+type EmojiSet = {+ css: {use: () => void; unuse: () => void};+ sheet: string;+};++const emojisets = new Map<string, EmojiSet>([["google", {css: google_css, sheet: google_sheet}],["google-blob", {css: google_blob_css, sheet: google_blob_sheet}],["twitter", {css: twitter_css, sheet: twitter_sheet}],@@ -18,15 +23,20 @@ const emojisets = new Map([// For `text` emoji set we fallback to `google` emoji set// for displaying emojis in emoji picker and typeahead.-emojisets.set("text", emojisets.get("google"));+emojisets.set("text", emojisets.get("google")!);-let current_emojiset;+let current_emojiset: EmojiSet | undefined;-export async function select(name) {+export async function select(name: string): Promise<void> {const new_emojiset = emojisets.get(name);if (new_emojiset === current_emojiset) {return;}++ if (!new_emojiset) {+ throw new Error("Unknown emojiset " + name);+ }+await new Promise((resolve, reject) => {const sheet = new Image();sheet.addEventListener("load", resolve);@@ -45,8 +55,8 @@ export async function select(name) {current_emojiset = new_emojiset;}-export function initialize() {- select(user_settings.emojiset);+export function initialize(): void {+ void select(user_settings.emojiset);// Load the octopus image in the background, so that the browser// will cache it for later use. Note that we hardcode the octopus