ts: Convert `compose_textarea.js` to TypeScript.

Added type definitions for `jquery-caret-plugin` third party package and
converted `compose_textarea.js` to TypeScript.
This commit is contained in:
Lalit 2023-05-25 14:04:37 +05:30 committed by Tim Abbott
parent 48e99657ad
commit 38dd1de5b2
3 changed files with 20 additions and 4 deletions

View File

@ -67,7 +67,7 @@ EXEMPT_FILES = make_set(
"web/src/compose_fade.js", "web/src/compose_fade.js",
"web/src/compose_recipient.js", "web/src/compose_recipient.js",
"web/src/compose_state.js", "web/src/compose_state.js",
"web/src/compose_textarea.js", "web/src/compose_textarea.ts",
"web/src/compose_ui.js", "web/src/compose_ui.js",
"web/src/compose_validate.js", "web/src/compose_validate.js",
"web/src/composebox_typeahead.js", "web/src/composebox_typeahead.js",

View File

@ -4,7 +4,7 @@ import $ from "jquery";
// shift-tab back in (see hotkey.js). // shift-tab back in (see hotkey.js).
let saved_compose_cursor = 0; let saved_compose_cursor = 0;
function set_compose_textarea_handlers() { function set_compose_textarea_handlers(): void {
$("#compose-textarea").on("blur", function () { $("#compose-textarea").on("blur", function () {
saved_compose_cursor = $(this).caret(); saved_compose_cursor = $(this).caret();
}); });
@ -16,10 +16,10 @@ function set_compose_textarea_handlers() {
}); });
} }
export function restore_compose_cursor() { export function restore_compose_cursor(): void {
$("#compose-textarea").trigger("focus").caret(saved_compose_cursor); $("#compose-textarea").trigger("focus").caret(saved_compose_cursor);
} }
export function initialize() { export function initialize(): void {
set_compose_textarea_handlers(); set_compose_textarea_handlers();
} }

16
web/src/global.d.ts vendored
View File

@ -5,10 +5,26 @@
declare let zulip_test: any; // eslint-disable-line @typescript-eslint/no-explicit-any declare let zulip_test: any; // eslint-disable-line @typescript-eslint/no-explicit-any
type JQueryCaretRange = {
start: number;
end: number;
length: number;
text: string;
};
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface JQuery { interface JQuery {
expectOne(): JQuery; expectOne(): JQuery;
tab(action?: string): this; // From web/third/bootstrap tab(action?: string): this; // From web/third/bootstrap
// Types for jquery-caret-plugin
caret(): number;
caret(arg: number | string): this;
range(): JQueryCaretRange;
range(start: number, end?: number): this;
range(text: string): this;
selectAll(): this;
deselectAll(): this;
} }
declare const ZULIP_VERSION: string; declare const ZULIP_VERSION: string;