1- const vscode = require ( "vscode" ) ;
2- const ui5APIService = require ( "../core/ui5ApiService.js" ) ;
3- const ui5APIFormatter = require ( "../objectApi/objectApiFormat.js" ) ;
4- const ui5APIFinder = require ( "../search/ui5ApiFinder.js" ) ;
5- const constants = require ( "../core/constants.js" ) ;
6- const favorites = require ( "../panelFeatures/favorites" ) ;
7- const filtering = require ( "../panelFeatures/apiDocsFiltering" ) ;
8- const Mustache = require ( "mustache" ) ;
9-
10- class APIReferenceCtrl {
11- constructor ( webviewView , templates ) {
1+ import * as vscode from "vscode" ;
2+ import * as ui5APIService from "../core/ui5ApiService" ;
3+ import * as ui5APIFormatter from "../objectApi/objectApiFormat" ;
4+ import * as ui5APIFinder from "../search/ui5ApiFinder" ;
5+ import * as constants from "../core/constants" ;
6+ import * as favorites from "../panelFeatures/favorites" ;
7+ import * as filtering from "../panelFeatures/apiDocsFiltering" ;
8+ import * as mustache from "mustache" ;
9+ import { TemplatesContent } from "../core/dataSource" ;
10+
11+ interface GlobalState {
12+ hitlistObjectsLimit : number ;
13+ visibleObjectName : string | null ;
14+ }
15+
16+ interface SearchState {
17+ previousSearchedObjectName : string | null ;
18+ searchedObjectName : string | null ;
19+ memberSearchString : string | null ;
20+ memberGroupFilter : string | null ;
21+ searchTimeout ?: ReturnType < typeof setTimeout > ;
22+ }
23+
24+ interface SearchMessage {
25+ searchInput : string ;
26+ }
27+
28+ interface GetDesignApiMessage {
29+ source ?: string ;
30+ ui5Object : string ;
31+ }
32+
33+ interface ChangeFavoriteMessage {
34+ operation : string ;
35+ ui5Object : string ;
36+ }
37+
38+ export class ApiReferenceCtrl {
39+ private _webviewView : vscode . WebviewView ;
40+ private _templates : TemplatesContent ;
41+ private _globalState : GlobalState ;
42+ private _searchState : SearchState ;
43+
44+ constructor ( webviewView : vscode . WebviewView , templates : TemplatesContent ) {
1245 this . _webviewView = webviewView ;
1346 this . _templates = templates ;
1447
1548 const configuration = vscode . workspace . getConfiguration ( "UI5ReferencePanel" ) ;
1649
1750 this . _globalState = {
18- hitlistObjectsLimit : configuration . get ( "hitlistSize" ) ,
51+ hitlistObjectsLimit : configuration . get ( "hitlistSize" ) as number ,
1952 visibleObjectName : null ,
2053 } ;
2154
@@ -24,11 +57,10 @@ class APIReferenceCtrl {
2457 searchedObjectName : null ,
2558 memberSearchString : null ,
2659 memberGroupFilter : null ,
27- searchTimeout : 0 ,
2860 } ;
2961 }
3062
31- handleSearch ( message ) {
63+ handleSearch ( message : SearchMessage ) {
3264 clearTimeout ( this . _searchState . searchTimeout ) ;
3365 const searchInput = message . searchInput ;
3466
@@ -43,8 +75,8 @@ class APIReferenceCtrl {
4375
4476 if ( this . _globalState . visibleObjectName ) {
4577 this . handleGetDesignAPIHtml (
46- { ui5Object : this . _globalState . visibleObjectName } ,
47- "oneSearchResult"
78+ { ui5Object : this . _globalState . visibleObjectName }
79+ // "oneSearchResult"
4880 ) ;
4981 }
5082 }
@@ -81,8 +113,8 @@ class APIReferenceCtrl {
81113 }
82114
83115 this . handleGetDesignAPIHtml (
84- { ui5Object : this . _globalState . visibleObjectName } ,
85- "oneSearchResult"
116+ { ui5Object : this . _globalState . visibleObjectName }
117+ // "oneSearchResult"
86118 ) ;
87119
88120 return ;
@@ -134,7 +166,7 @@ class APIReferenceCtrl {
134166 } ) ;
135167
136168 const configuration = vscode . workspace . getConfiguration ( "UI5ReferencePanel" ) ;
137- this . _globalState . hitlistObjectsLimit = configuration . get ( "hitlistSize" ) ;
169+ this . _globalState . hitlistObjectsLimit = configuration . get ( "hitlistSize" ) as number ;
138170
139171 if ( foundObjects && foundObjects . length > 0 ) {
140172 if ( foundObjects . length > this . _globalState . hitlistObjectsLimit ) {
@@ -151,7 +183,7 @@ class APIReferenceCtrl {
151183 result : foundObjects ,
152184 } ) ;
153185 } else {
154- this . handleGetDesignAPIHtml ( { ui5Object : foundObjects [ 0 ] . name } , "oneSearchResult" ) ;
186+ this . handleGetDesignAPIHtml ( { ui5Object : foundObjects [ 0 ] . name } ) ; // , "oneSearchResult");
155187 }
156188 } else {
157189 this . _webviewView . webview . postMessage ( {
@@ -162,12 +194,12 @@ class APIReferenceCtrl {
162194 } , 500 ) ;
163195 }
164196
165- handleGetDesignAPIHtml ( message ) {
197+ handleGetDesignAPIHtml ( message : GetDesignApiMessage ) {
166198 this . _globalState . visibleObjectName = message . ui5Object ;
167199
168200 if ( message . source === "favorite" ) {
169- this . _searchState . memberGroupFilter = undefined ;
170- this . _searchState . memberSearchString = undefined ;
201+ this . _searchState . memberGroupFilter = null ;
202+ this . _searchState . memberSearchString = null ;
171203 }
172204
173205 const designAPIHtml = this . getDesignAPIHtml ( message . ui5Object ) ;
@@ -192,11 +224,11 @@ class APIReferenceCtrl {
192224 }
193225 }
194226
195- handleOpenURL ( apiDocURL ) {
227+ handleOpenURL ( apiDocURL : string ) {
196228 vscode . env . openExternal ( vscode . Uri . parse ( apiDocURL ) ) ;
197229 }
198230
199- handleChangeFavorite ( message ) {
231+ handleChangeFavorite ( message : ChangeFavoriteMessage ) {
200232 if ( message . operation === "remove" ) {
201233 favorites . removeFavorite ( message . ui5Object ) ;
202234 } else {
@@ -209,8 +241,8 @@ class APIReferenceCtrl {
209241 } ) ;
210242 }
211243
212- getDesignAPI ( ui5ObjectPath ) {
213- let designApi = ui5APIService . getUi5ObjectDesignApi ( ui5ObjectPath ) ;
244+ getDesignAPI ( ui5ObjectName : string ) {
245+ let designApi = ui5APIService . getUi5ObjectDesignApi ( ui5ObjectName ) ;
214246
215247 if ( ! designApi ) {
216248 return ;
@@ -227,7 +259,7 @@ class APIReferenceCtrl {
227259 return ui5APIFormatter . getFormattedObjectApi ( designApi , true , true ) ;
228260 }
229261
230- triggerSearch ( input ) {
262+ triggerSearch ( input : string ) {
231263 this . _webviewView . webview . postMessage ( {
232264 type : "triggerSearch" ,
233265 input,
@@ -243,17 +275,15 @@ class APIReferenceCtrl {
243275 } ) ;
244276 }
245277
246- getDesignAPIHtml ( ui5Object ) {
247- const designAPI = this . getDesignAPI ( ui5Object ) ;
278+ getDesignAPIHtml ( ui5ObjectName : string ) {
279+ const designAPI = this . getDesignAPI ( ui5ObjectName ) ;
248280
249281 if ( ! designAPI ) {
250282 return null ;
251283 } else {
252- return Mustache . render ( this . _templates . objectAPI , designAPI , {
284+ return mustache . render ( this . _templates . objectAPI , designAPI , {
253285 membersTemplate : this . _templates . members ,
254286 } ) ;
255287 }
256288 }
257289}
258-
259- module . exports = APIReferenceCtrl ;
0 commit comments