diff --git a/.eslintrc.json b/.eslintrc.json index 3d30288050..accbe31e72 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -143,7 +143,6 @@ "drafts": false, "dropdown_list_widget": false, "echo": false, - "emoji": false, "emoji_picker": false, "favicon": false, "feature_flags": false, diff --git a/frontend_tests/node_tests/composebox_typeahead.js b/frontend_tests/node_tests/composebox_typeahead.js index dc9cfbc0ec..d78682abde 100644 --- a/frontend_tests/node_tests/composebox_typeahead.js +++ b/frontend_tests/node_tests/composebox_typeahead.js @@ -1,7 +1,7 @@ +const emoji = zrequire("emoji", "shared/js/emoji"); const typeahead = zrequire("typeahead", "shared/js/typeahead"); zrequire("compose_state"); zrequire("pm_conversations"); -zrequire("emoji"); set_global("Handlebars", global.make_handlebars()); zrequire("templates"); zrequire("typeahead_helper"); diff --git a/frontend_tests/node_tests/dispatch.js b/frontend_tests/node_tests/dispatch.js index ecbf8344b5..8c6b2aac3d 100644 --- a/frontend_tests/node_tests/dispatch.js +++ b/frontend_tests/node_tests/dispatch.js @@ -66,7 +66,6 @@ const page_params = global.page_params; // For data-oriented modules, just use them, don't stub them. zrequire("alert_words"); -zrequire("emoji"); zrequire("unread"); zrequire("stream_topic_history"); zrequire("stream_list"); @@ -77,6 +76,8 @@ zrequire("starred_messages"); zrequire("user_status"); zrequire("subs"); +const emoji = zrequire("emoji", "shared/js/emoji"); + zrequire("server_events_dispatch"); zrequire("panels"); diff --git a/frontend_tests/node_tests/emoji.js b/frontend_tests/node_tests/emoji.js index 633f5a8cb1..48f2167c16 100644 --- a/frontend_tests/node_tests/emoji.js +++ b/frontend_tests/node_tests/emoji.js @@ -2,7 +2,7 @@ const emoji_codes = zrequire("emoji_codes", "generated/emoji/emoji_codes.json"); const events = require("./lib/events.js"); -zrequire("emoji"); +const emoji = zrequire("emoji", "shared/js/emoji"); const realm_emoji = events.fixtures.realm_emoji.realm_emoji; diff --git a/frontend_tests/node_tests/emoji_picker.js b/frontend_tests/node_tests/emoji_picker.js index abb5ae114e..6e7ddadd5a 100644 --- a/frontend_tests/node_tests/emoji_picker.js +++ b/frontend_tests/node_tests/emoji_picker.js @@ -1,4 +1,4 @@ -zrequire("emoji"); +const emoji = zrequire("emoji", "shared/js/emoji"); zrequire("emoji_picker"); const emoji_codes = zrequire("emoji_codes", "generated/emoji/emoji_codes.json"); diff --git a/frontend_tests/node_tests/hotkey.js b/frontend_tests/node_tests/hotkey.js index 104185774a..1b3434abc9 100644 --- a/frontend_tests/node_tests/hotkey.js +++ b/frontend_tests/node_tests/hotkey.js @@ -27,7 +27,7 @@ set_global("overlays", {}); set_global("document", "document-stub"); set_global("$", global.make_zjquery()); -zrequire("emoji"); +const emoji = zrequire("emoji", "shared/js/emoji"); emoji.initialize({ realm_emoji: {}, diff --git a/frontend_tests/node_tests/markdown.js b/frontend_tests/node_tests/markdown.js index 2dec9cce97..c3a222b9d0 100644 --- a/frontend_tests/node_tests/markdown.js +++ b/frontend_tests/node_tests/markdown.js @@ -1,11 +1,11 @@ zrequire("hash_util"); set_global("marked", zrequire("marked", "third/marked/lib/marked")); +const emoji = zrequire("emoji", "shared/js/emoji"); const emoji_codes = zrequire("emoji_codes", "generated/emoji/emoji_codes.json"); const fenced_code = zrequire("fenced_code", "shared/js/fenced_code"); const markdown_config = zrequire("markdown_config"); -zrequire("emoji"); zrequire("markdown"); zrequire("message_store"); zrequire("people"); diff --git a/frontend_tests/node_tests/markdown_katex.js b/frontend_tests/node_tests/markdown_katex.js index 3348088381..7f9dc0b738 100644 --- a/frontend_tests/node_tests/markdown_katex.js +++ b/frontend_tests/node_tests/markdown_katex.js @@ -12,7 +12,6 @@ const markdown_config = zrequire("markdown_config"); set_global("marked", zrequire("marked", "third/marked/lib/marked")); set_global("page_params", {}); -zrequire("emoji"); zrequire("hash_util"); zrequire("message_store"); zrequire("people"); diff --git a/frontend_tests/node_tests/reactions.js b/frontend_tests/node_tests/reactions.js index f32458d499..b002ed1775 100644 --- a/frontend_tests/node_tests/reactions.js +++ b/frontend_tests/node_tests/reactions.js @@ -2,8 +2,8 @@ set_global("document", "document-stub"); set_global("$", global.make_zjquery()); const emoji_codes = zrequire("emoji_codes", "generated/emoji/emoji_codes.json"); +const emoji = zrequire("emoji", "shared/js/emoji"); -zrequire("emoji"); zrequire("people"); zrequire("reactions"); diff --git a/frontend_tests/node_tests/typeahead_helper.js b/frontend_tests/node_tests/typeahead_helper.js index 3ed606a294..0f01c33c9b 100644 --- a/frontend_tests/node_tests/typeahead_helper.js +++ b/frontend_tests/node_tests/typeahead_helper.js @@ -9,11 +9,12 @@ set_global("Handlebars", global.make_handlebars()); zrequire("recent_senders"); zrequire("pm_conversations"); zrequire("people"); -zrequire("emoji"); zrequire("stream_data"); zrequire("narrow"); zrequire("hash_util"); zrequire("marked", "third/marked/lib/marked"); + +const emoji = zrequire("emoji", "shared/js/emoji"); const pygments_data = zrequire("pygments_data", "generated/pygments_data.json"); const actual_pygments_data = Object.assign({}, pygments_data); const ct = zrequire("composebox_typeahead"); diff --git a/frontend_tests/node_tests/ui_init.js b/frontend_tests/node_tests/ui_init.js index ecab8005bf..9a03b26ae8 100644 --- a/frontend_tests/node_tests/ui_init.js +++ b/frontend_tests/node_tests/ui_init.js @@ -21,6 +21,7 @@ const rewiremock = require("rewiremock/node"); */ const util = zrequire("util"); + set_global("document", { location: { protocol: "http", @@ -74,7 +75,6 @@ ui.get_scroll_element = (element) => element; zrequire("alert_words"); zrequire("hash_util"); zrequire("echo"); -zrequire("emoji"); zrequire("colorspace"); zrequire("stream_color"); zrequire("stream_edit"); diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js index e956cb68bd..29efcaad8d 100644 --- a/static/js/bundles/app.js +++ b/static/js/bundles/app.js @@ -182,7 +182,6 @@ import "../settings_profile_fields.js"; import "../settings.js"; import "../admin.js"; import "../tab_bar.js"; -import "../emoji.js"; import "../bot_data.js"; import "../reactions.js"; import "../typing.js"; diff --git a/static/js/composebox_typeahead.js b/static/js/composebox_typeahead.js index b306e1ad58..3527bba2bb 100644 --- a/static/js/composebox_typeahead.js +++ b/static/js/composebox_typeahead.js @@ -2,6 +2,7 @@ const autosize = require("autosize"); const confirmDatePlugin = require("flatpickr/dist/plugins/confirmDate/confirmDate.js"); const pygments_data = require("../generated/pygments_data.json"); +const emoji = require("../shared/js/emoji"); const typeahead = require("../shared/js/typeahead"); const settings_data = require("./settings_data"); diff --git a/static/js/emoji_picker.js b/static/js/emoji_picker.js index 710fe3ac90..f2240724f0 100644 --- a/static/js/emoji_picker.js +++ b/static/js/emoji_picker.js @@ -1,4 +1,5 @@ const emoji_codes = require("../generated/emoji/emoji_codes.json"); +const emoji = require("../shared/js/emoji"); const typeahead = require("../shared/js/typeahead"); const render_emoji_popover = require("../templates/emoji_popover.hbs"); const render_emoji_popover_content = require("../templates/emoji_popover_content.hbs"); diff --git a/static/js/hotkey.js b/static/js/hotkey.js index fed8f8acdd..7c0528d5d7 100644 --- a/static/js/hotkey.js +++ b/static/js/hotkey.js @@ -1,3 +1,5 @@ +const emoji = require("../shared/js/emoji"); + function do_narrow_action(action) { action(current_msg_list.selected_id(), {trigger: "hotkey"}); return true; diff --git a/static/js/markdown_config.js b/static/js/markdown_config.js index 4cfb8e6786..8789e0a0ef 100644 --- a/static/js/markdown_config.js +++ b/static/js/markdown_config.js @@ -1,3 +1,6 @@ +// TODO: move to markdown. +const emoji = require("../shared/js/emoji"); + /* This config is in a separate file for partly tactical reasons. We want the webapp to diff --git a/static/js/reactions.js b/static/js/reactions.js index f3acea867f..33edd7c9bc 100644 --- a/static/js/reactions.js +++ b/static/js/reactions.js @@ -1,3 +1,4 @@ +const emoji = require("../shared/js/emoji"); const render_message_reaction = require("../templates/message_reaction.hbs"); exports.view = {}; // function namespace diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.js index 25135bbfed..d7f4d08f6f 100644 --- a/static/js/server_events_dispatch.js +++ b/static/js/server_events_dispatch.js @@ -1,3 +1,5 @@ +const emoji = require("../shared/js/emoji"); + const settings_config = require("./settings_config"); exports.dispatch_normal_event = function dispatch_normal_event(event) { diff --git a/static/js/settings_emoji.js b/static/js/settings_emoji.js index 48636eaa18..8f7b71fbc2 100644 --- a/static/js/settings_emoji.js +++ b/static/js/settings_emoji.js @@ -1,3 +1,4 @@ +const emoji = require("../shared/js/emoji"); const render_admin_emoji_list = require("../templates/admin_emoji_list.hbs"); const render_settings_emoji_settings_tip = require("../templates/settings/emoji_settings_tip.hbs"); diff --git a/static/js/typeahead_helper.js b/static/js/typeahead_helper.js index 410a35762c..c14d4f3c58 100644 --- a/static/js/typeahead_helper.js +++ b/static/js/typeahead_helper.js @@ -1,4 +1,5 @@ const pygments_data = require("../generated/pygments_data.json"); +const emoji = require("../shared/js/emoji"); const typeahead = require("../shared/js/typeahead"); const render_typeahead_list_item = require("../templates/typeahead_list_item.hbs"); diff --git a/static/js/ui_init.js b/static/js/ui_init.js index e8206fa11d..f8cfa2170c 100644 --- a/static/js/ui_init.js +++ b/static/js/ui_init.js @@ -1,4 +1,5 @@ const generated_emoji_codes = require("../generated/emoji/emoji_codes.json"); +const emoji = require("../shared/js/emoji"); const emojisets = require("./emojisets"); const markdown_config = require("./markdown_config"); diff --git a/static/js/emoji.js b/static/shared/js/emoji.js similarity index 74% rename from static/js/emoji.js rename to static/shared/js/emoji.js index 735ae44a6f..6d9f9bc75c 100644 --- a/static/js/emoji.js +++ b/static/shared/js/emoji.js @@ -4,10 +4,10 @@ let emoji_codes = {}; // `emojis_by_name` is the central data source that is supposed to be // used by every widget in the webapp for gathering data for displaying // emojis. Emoji picker uses this data to derive data for its own use. -exports.emojis_by_name = new Map(); +export const emojis_by_name = new Map(); -exports.all_realm_emojis = new Map(); -exports.active_realm_emojis = new Map(); +export const all_realm_emojis = new Map(); +export const active_realm_emojis = new Map(); const default_emoji_aliases = new Map(); @@ -19,7 +19,9 @@ const default_emoji_aliases = new Map(); let server_realm_emoji_data = {}; // We really want to deprecate this, too. -exports.get_server_realm_emoji_data = () => server_realm_emoji_data; +export function get_server_realm_emoji_data() { + return server_realm_emoji_data; +} function escape_regexp(string) { // HIGHLY DEPRECATED!!!! @@ -74,26 +76,26 @@ const zulip_emoji = { deactivated: false, }; -exports.get_emoji_name = (codepoint) => { +export function get_emoji_name(codepoint) { // get_emoji_name('1f384') === 'holiday_tree' if (Object.prototype.hasOwnProperty.call(emoji_codes.codepoint_to_name, codepoint)) { return emoji_codes.codepoint_to_name[codepoint]; } -}; +} -exports.get_emoji_codepoint = (emoji_name) => { +export function get_emoji_codepoint(emoji_name) { // get_emoji_codepoint('avocado') === '1f951' if (Object.prototype.hasOwnProperty.call(emoji_codes.name_to_codepoint, emoji_name)) { return emoji_codes.name_to_codepoint[emoji_name]; } -}; +} -exports.get_realm_emoji_url = (emoji_name) => { +export function get_realm_emoji_url(emoji_name) { // If the emoji name is a realm emoji, returns the URL for it. // Returns undefined for unicode emoji. // get_realm_emoji_url('shrug') === '/user_avatars/2/emoji/images/31.png' - const data = exports.active_realm_emojis.get(emoji_name); + const data = active_realm_emojis.get(emoji_name); if (!data) { // Not all emojis have urls, plus the user @@ -106,10 +108,10 @@ exports.get_realm_emoji_url = (emoji_name) => { } return data.emoji_url; -}; +} -exports.build_emoji_data = function (realm_emojis) { - exports.emojis_by_name.clear(); +export function build_emoji_data(realm_emojis) { + emojis_by_name.clear(); for (const [realm_emoji_name, realm_emoji] of realm_emojis) { const emoji_dict = { name: realm_emoji_name, @@ -119,13 +121,13 @@ exports.build_emoji_data = function (realm_emojis) { url: realm_emoji.emoji_url, has_reacted: false, }; - exports.emojis_by_name.set(realm_emoji_name, emoji_dict); + emojis_by_name.set(realm_emoji_name, emoji_dict); } for (const codepoints of Object.values(emoji_codes.emoji_catalog)) { for (const codepoint of codepoints) { - const emoji_name = exports.get_emoji_name(codepoint); - if (emoji_name !== undefined && !exports.emojis_by_name.has(emoji_name)) { + const emoji_name = get_emoji_name(codepoint); + if (emoji_name !== undefined && !emojis_by_name.has(emoji_name)) { const emoji_dict = { name: emoji_name, display_name: emoji_name, @@ -134,32 +136,32 @@ exports.build_emoji_data = function (realm_emojis) { emoji_code: codepoint, has_reacted: false, }; - exports.emojis_by_name.set(emoji_name, emoji_dict); + emojis_by_name.set(emoji_name, emoji_dict); } } } -}; +} -exports.update_emojis = function (realm_emojis) { +export function update_emojis(realm_emojis) { // The settings code still works with the // server format of the data. server_realm_emoji_data = realm_emojis; - // exports.all_realm_emojis is emptied before adding the realm-specific emoji + // all_realm_emojis is emptied before adding the realm-specific emoji // to it. This makes sure that in case of deletion, the deleted realm_emojis - // don't persist in exports.active_realm_emojis. - exports.all_realm_emojis.clear(); - exports.active_realm_emojis.clear(); + // don't persist in active_realm_emojis. + all_realm_emojis.clear(); + active_realm_emojis.clear(); for (const data of Object.values(realm_emojis)) { - exports.all_realm_emojis.set(data.id, { + all_realm_emojis.set(data.id, { id: data.id, emoji_name: data.name, emoji_url: data.source_url, deactivated: data.deactivated, }); if (data.deactivated !== true) { - exports.active_realm_emojis.set(data.name, { + active_realm_emojis.set(data.name, { id: data.id, emoji_name: data.name, emoji_url: data.source_url, @@ -167,19 +169,19 @@ exports.update_emojis = function (realm_emojis) { } } // Add the Zulip emoji to the realm emojis list - exports.all_realm_emojis.set("zulip", zulip_emoji); - exports.active_realm_emojis.set("zulip", zulip_emoji); + all_realm_emojis.set("zulip", zulip_emoji); + active_realm_emojis.set("zulip", zulip_emoji); - exports.build_emoji_data(exports.active_realm_emojis); -}; + build_emoji_data(active_realm_emojis); +} -exports.initialize = function initialize(params) { +export function initialize(params) { emoji_codes = params.emoji_codes; build_emoticon_translations(); for (const value of emoji_codes.names) { - const base_name = exports.get_emoji_codepoint(value); + const base_name = get_emoji_codepoint(value); if (default_emoji_aliases.has(base_name)) { default_emoji_aliases.get(base_name).push(value); @@ -188,22 +190,22 @@ exports.initialize = function initialize(params) { } } - exports.update_emojis(params.realm_emoji); -}; + update_emojis(params.realm_emoji); +} -exports.get_canonical_name = function (emoji_name) { - if (exports.active_realm_emojis.has(emoji_name)) { +export function get_canonical_name(emoji_name) { + if (active_realm_emojis.has(emoji_name)) { return emoji_name; } - const codepoint = exports.get_emoji_codepoint(emoji_name); + const codepoint = get_emoji_codepoint(emoji_name); if (codepoint === undefined) { // Our caller needs to handle this possibility. return; } - return exports.get_emoji_name(codepoint); -}; + return get_emoji_name(codepoint); +} -exports.get_emoticon_translations = () => emoticon_translations; - -window.emoji = exports; +export function get_emoticon_translations() { + return emoticon_translations; +}