From a46147588f61070d1ed6f9e559cff718d7d33f85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCl=C5=9Fah=20K=C3=B6se?= Date: Mon, 6 May 2024 14:27:08 +0300 Subject: [PATCH] Convert Control.Mention.js to Control.Mention.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gülşah Köse Change-Id: I575d9e14562b1a77f30d355024a2106d7955fe6a --- browser/.beforeprettier | 2 +- browser/Makefile.am | 2 +- ...{Control.Mention.js => Control.Mention.ts} | 77 +++++++++++++++---- 3 files changed, 66 insertions(+), 15 deletions(-) rename browser/src/control/{Control.Mention.js => Control.Mention.ts} (80%) diff --git a/browser/.beforeprettier b/browser/.beforeprettier index 55e00aab4e..381951b60b 100644 --- a/browser/.beforeprettier +++ b/browser/.beforeprettier @@ -21,7 +21,7 @@ /src/control/Control.LanguageDialog.js /src/control/Control.Layers.js /src/control/Control.LokDialog.js -/src/control/Control.Mention.js +/src/control/Control.Mention.ts /src/control/Control.Menubar.js /src/control/Control.MobileBottomBar.js /src/control/Control.MobileSlide.js diff --git a/browser/Makefile.am b/browser/Makefile.am index 0ae3161096..c23431c8b7 100644 --- a/browser/Makefile.am +++ b/browser/Makefile.am @@ -382,7 +382,7 @@ COOL_JS_LST =\ src/control/Control.NotebookbarBuilder.js \ src/control/Control.Layers.js \ src/control/Control.Sidebar.js \ - src/control/Control.Mention.js \ + src/control/Control.Mention.ts \ src/control/Control.Zotero.js \ src/control/Search.js \ src/control/Permission.js \ diff --git a/browser/src/control/Control.Mention.js b/browser/src/control/Control.Mention.ts similarity index 80% rename from browser/src/control/Control.Mention.js rename to browser/src/control/Control.Mention.ts index 9e0919d196..cf21701790 100644 --- a/browser/src/control/Control.Mention.js +++ b/browser/src/control/Control.Mention.ts @@ -14,8 +14,53 @@ /* global app */ +interface Data { + jsontype: string; + id: string; + control: Control; + posx: number; + posy: number; + children: Array; +} + +interface Entry { + text: string; + columns: { text: any; }[]; + row: string; +} + +interface Control { + id: string; + type: string; + text: string; + enabled: boolean; + singleclickactivate: boolean; + fireKeyEvents: boolean; + entries: Array; +} + +interface Children { + id: string; + type: string; + text: string; + enabled: boolean; + children: Array; + vertical: boolean; +} + +interface PopupData { + children: Children; + jsontype: string; + type: string; + isMention: boolean; + cancellable: boolean; + popupParent: string; + clickToClose: string; + id: string; +} + L.Control.Mention = L.Control.extend({ - onAdd: function(map) { + onAdd: function(map: ReturnType) { this.map = map; this.map.on('openmentionpopup', this.openMentionPopup, this); this.map.on('closementionpopup', this.closeMentionPopup, this); @@ -44,7 +89,7 @@ L.Control.Mention = L.Control.extend({ this.itemList = null; }, - sendMentionText: function(ev) { + sendMentionText: function(ev: MessageEvent) { var text = ev.data.join('').substring(1); if (text.length === 1 && this.firstChar !== text[0]) { this.map.fire('postMessage', { msgId: 'UI_Mention', args: { type: 'autocomplete', text: text } }); @@ -61,7 +106,7 @@ L.Control.Mention = L.Control.extend({ return new L.Point(Math.round(currPos.x + panePos.x - origin.x), Math.round(currPos.y + panePos.y - origin.y)); }, - openMentionPopup: function(ev) { + openMentionPopup: function(ev: MessageEvent) { var framePos = this.getCurrentCursorPosition(); this.users = ev.data; if (this.users === null) @@ -93,25 +138,27 @@ L.Control.Mention = L.Control.extend({ entries.push(entry); } - var data; - var control = { + var data: Data; + var control: Control = { 'id': 'mentionList', 'type': 'treelistbox', 'text': '', 'enabled': true, 'singleclickactivate': false, - 'fireKeyEvents': true + 'fireKeyEvents': true, + 'entries': [] }; // update the popup with list if mentionList already exist if (L.DomUtil.get('mentionList')) { data = { 'jsontype': 'dialog', 'id': 'mentionPopup', - 'control': control + 'control': control, + 'posx': framePos.x, + 'posy': framePos.y, + 'children': undefined }; data.control.entries = entries; - data.posx = framePos.x; - data.posy = framePos.y; this.map.fire('jsdialogupdate', { data: data, callback: this.callback.bind(this) }); return; } @@ -121,20 +168,24 @@ L.Control.Mention = L.Control.extend({ data.children[0].children[0] = control; data.children[0].children[0].entries = entries; } else { - var control = { + var control: Control = { 'id': 'fixedtext', 'type': 'fixedtext', 'text': 'no search results found!', 'enabled': true, + 'singleclickactivate': undefined, + 'fireKeyEvents': undefined, + 'entries': undefined }; if (L.DomUtil.get('fixedtext')) { data = { 'jsontype': 'dialog', 'id': 'mentionPopup', - 'control': control + 'control': control, + 'posx': framePos.x, + 'posy': framePos.y, + 'children': undefined }; - data.posx = framePos.x; - data.posy = framePos.y; this.map.fire('jsdialogupdate', { data: data, callback: this.callback.bind(this) }); return; }