Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Commit f55ce9d

Browse files
committed
Add JSDoc to components and services
Bug: 193062584 Bug: 193437013 Change-Id: Ia016228ba9811e499aace074e30788a4bd9c706d
1 parent eccfdc3 commit f55ce9d

File tree

10 files changed

+111
-9
lines changed

10 files changed

+111
-9
lines changed

src/app/app.component.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import {MatTabChangeEvent} from '@angular/material/tabs';
1919
import {ChromeBridgeService} from './chrome-bridge.service';
2020
import {PreferencesService} from './preferences.service';
2121

22+
/**
23+
* Primary component that encompasses the Chrome Extension.
24+
*/
2225
@Component({
2326
selector: 'app-root',
2427
templateUrl: './app.component.html',
@@ -37,6 +40,12 @@ export class AppComponent {
3740
this.preferences = preferences;
3841
}
3942

43+
/**
44+
* Event that executes when the selected tab changes. This can be used to
45+
* pull or push data between the extension and client. Currently it will
46+
* re-fetch the Interactive Canvas app history.
47+
* @param event Generated event on each tab change
48+
*/
4049
async tabChanged(event: MatTabChangeEvent) {
4150
const {index} = event;
4251
const debugExtension = await this.preferences.getFlagDebugExtension();

src/app/preferences.service.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {Injectable} from '@angular/core';
1919

2020
/**
2121
* Every setting should have getters/setters that work with Chrome storage API.
22-
* See https://developer.chrome.com/docs/extensions/reference/storage/
2322
*/
2423
interface ExtensionPreferences {
2524
/**
@@ -34,6 +33,12 @@ interface ExtensionPreferences {
3433

3534
type ExtensionPreference = keyof ExtensionPreferences;
3635

36+
/**
37+
* The Preferences service manages extension-wide preferences in a persistent
38+
* manner. It synchronizes changes with the browser preferences so that
39+
* they persist between sessions and between browser instances.
40+
* @see https://developer.chrome.com/docs/extensions/reference/storage/
41+
*/
3742
@Injectable({
3843
providedIn: 'root',
3944
})

src/app/tab-history/tab-history.component.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ interface SortedCanvasHistory extends CanvasHistory {
3636
relativeTime: string;
3737
}
3838

39+
/**
40+
* The History tab displays a record of outbound Interactive Canvas
41+
* events and displays them in chronological order starting from the
42+
* most-recent. Canvas state changes will show more precise line-by-line
43+
* diffs in greater detail.
44+
*/
3945
@Component({
4046
selector: 'tab-history',
4147
templateUrl: './tab-history.component.html',
@@ -63,6 +69,11 @@ export class TabHistoryComponent implements OnInit {
6369
});
6470
}
6571

72+
/**
73+
* Switches the tab view to a colored diff between the currently selected
74+
* state event and the previous state event.
75+
* @param index Current index in the sortedHistory array, which is chronological
76+
*/
6677
openDiff(index: number): void {
6778
// Add listener for diff
6879
const entryCurrent = this.sortedHistory[index];
@@ -104,6 +115,9 @@ export class TabHistoryComponent implements OnInit {
104115
this.showList = false;
105116
}
106117

118+
/**
119+
* Exits the diff view and returns the view to the full list of events.
120+
*/
107121
exitDiff() {
108122
this.showList = true;
109123
}

src/app/tab-preferences/tab-preferences.component.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ import {MatSlideToggleChange} from '@angular/material/slide-toggle';
1919
import {ChromeBridgeService} from '../chrome-bridge.service';
2020
import {PreferencesService} from '../preferences.service';
2121

22+
/**
23+
* The Preferences tab displays available session-level capablities. It also
24+
* presents a number of extension settings to provide more developer control
25+
* over the debugging.
26+
*/
2227
@Component({
2328
selector: 'tab-preferences',
2429
templateUrl: './tab-preferences.component.html',
@@ -46,20 +51,34 @@ export class TabPreferencesComponent implements OnInit {
4651
await this.preferences.getFlagDebugExtension();
4752
}
4853

54+
/**
55+
* Click handler to show header on the webpage.
56+
*/
4957
showHeader() {
5058
this.chromeBridge.injectHeaderDom();
5159
}
5260

61+
/**
62+
* Click handler to prompt the user for the project SDK folder.
63+
*/
5364
loadSdk() {
5465
this.chromeBridge.loadSdk();
5566
}
5667

68+
/**
69+
* Click handler when the Debug Client toggle is changed.
70+
* @param event Toggle event
71+
*/
5772
async onChangeDebugClient(event: MatSlideToggleChange) {
5873
const {checked} = event;
5974
this.preferencesDebugClient = checked;
6075
await this.preferences.setFlagDebugClient(checked);
6176
}
6277

78+
/**
79+
* Click handler when the Debug Extension toggle is changed.
80+
* @param event Toggle event
81+
*/
6382
async onChangeDebugExtension(event: MatSlideToggleChange) {
6483
const {checked} = event;
6584
this.preferencesDebugExtension = checked;

src/app/tab-ttsmark/tab-ttsmark.component.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
import {Component, OnInit} from '@angular/core';
1818
import {ChromeBridgeService} from '../chrome-bridge.service';
1919

20+
/**
21+
* The TTS Mark tab allows one to send a custom TTS mark to the client.
22+
* Suggestion chips appear below the input prompt to fill in the prompt.
23+
*/
2024
@Component({
2125
selector: 'tab-ttsmark',
2226
templateUrl: './tab-ttsmark.component.html',
@@ -37,10 +41,18 @@ export class TabTtsmarkComponent implements OnInit {
3741
});
3842
}
3943

44+
/**
45+
* Click handler for suggestion chips, which will update the value of
46+
* the input field.
47+
* @param mark TTS Mark being selected
48+
*/
4049
prepopulate(mark: string) {
4150
this.markInput = mark;
4251
}
4352

53+
/**
54+
* Sends a TTS Mark to the client.
55+
*/
4456
run() {
4557
this.chromeBridge.sendOnTtsMark(this.markInput || '');
4658
}

src/app/tab-update/tab-update.component.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import {Component, OnInit} from '@angular/core';
1818
import jsonRepair from '../../utils/json-repair';
1919
import {ChromeBridgeService} from '../chrome-bridge.service';
2020

21+
/**
22+
* The Update tab allows one to send JSON data to the client. Suggestion
23+
* chips appear below the input prompt to fill in the prompt.
24+
*/
2125
@Component({
2226
selector: 'tab-update',
2327
templateUrl: './tab-update.component.html',
@@ -38,10 +42,18 @@ export class TabUpdateComponent implements OnInit {
3842
});
3943
}
4044

45+
/**
46+
* Click handler for suggestion chips, which will update the value of
47+
* the input field.
48+
* @param payload Stringified JSON being selected
49+
*/
4150
prepopulate(payload: string) {
4251
this.updateInput = payload;
4352
}
4453

54+
/**
55+
* Sends a properly formatted JSON string to the client.
56+
*/
4557
run() {
4658
const json = jsonRepair(this.updateInput || '{}');
4759
this.chromeBridge.sendOnUpdate(json);

src/content-script.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17+
/**
18+
* @fileoverview Event listeners that commuciate with the page without
19+
* interfering with normal page operations.
20+
* This runs in a sandbox, with restricted access to novel Window objects.
21+
*/
22+
1723
import {InteractiveCanvasWindow} from './types';
1824

1925
declare let window: InteractiveCanvasWindow;
@@ -31,9 +37,6 @@ scriptsToLoad.forEach(script => {
3137
};
3238
});
3339

34-
// Event listeners that commuciate with the page without interfering with
35-
// normal page operations.
36-
// This runs in a sandbox, with restricted access to novel Window objects.
3740
document.addEventListener('InteractiveCanvas_Init', (e: Event) => {
3841
const event = e as MessageEvent;
3942
window.interactiveCanvasExists = event.data;

src/interactive-canvas.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17+
/**
18+
* Types for Interactive Canvas.
19+
* @see https://developers.google.com/assistant/interactivecanvas/reference
20+
*/
1721
export interface InteractiveCanvas {
1822
ready: (callbacks: InteractiveCanvasCallbacks) => void;
1923
sendTextQuery: (textQuery: string) => Promise<State>;
@@ -24,6 +28,10 @@ export interface InteractiveCanvas {
2428
};
2529
}
2630

31+
/**
32+
* Types for Interactive Canvas callbacks.
33+
* @see https://developers.google.com/assistant/interactivecanvas/reference#interactivecanvascallbacks
34+
*/
2735
interface InteractiveCanvasCallbacks {
2836
onUpdate: (data: Object[]) => Promise<void> | undefined;
2937
onTtsMark: (markName: string) => void;

src/types.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,35 @@ export interface CanvasHistory {
2525
label: string;
2626
}
2727

28+
/**
29+
* @see https://wicg.github.io/file-system-access/#api-filesystemdirectoryhandle-getdirectoryhandle
30+
*/
2831
export interface DirectoryHandler {
2932
entries: () => FileIterator;
3033
getDirectoryHandle: (path: string) => Promise<DirectoryHandler>;
3134
getFileHandle: (path: string) => Promise<FileHandler>;
3235
}
3336

37+
/**
38+
* @see https://wicg.github.io/file-system-access/#api-filesystemdirectoryhandle-asynciterable
39+
*/
3440
export interface FileIterator {
3541
next: () => {
3642
done: boolean;
3743
value?: [string, FileHandler];
3844
};
3945
}
4046

47+
/**
48+
* @see https://wicg.github.io/file-system-access/#api-filesystemdirectoryhandle-getfilehandle
49+
*/
4150
export interface FileHandler {
4251
getFile: () => Promise<File>;
4352
}
4453

54+
/**
55+
* @see https://wicg.github.io/file-system-access/#api-filesystemfilehandle-getfile
56+
*/
4557
export interface File {
4658
slice: () => Promise<Blob>;
4759
text: () => Promise<string>;
@@ -69,16 +81,18 @@ export interface InteractiveCanvasWindow extends Window {
6981
title: string;
7082
projectId: string;
7183
/**
72-
* base64 representation of the project's logo
84+
* base64 representation of the project's logo.
7385
*/
7486
logoSrcData: string;
7587
};
7688
/**
77-
* JSYaml is a 3P library that converts YAML to JSON
89+
* JSYaml is a 3P library that converts YAML to JSON.
90+
* @see https://www.npmjs.com/package/js-yaml
7891
*/
7992
jsyaml: JSYaml;
8093
/**
81-
* A browser operation that opens a file directory selector
94+
* A browser operation that opens a file directory selector.
95+
* @see https://web.dev/file-system-access/
8296
*/
8397
showDirectoryPicker: () => Promise<DirectoryHandler>;
8498
}

src/webpage-script.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17+
/**
18+
* @fileoverview Code that runs in the context of the real page, without sandboxing.
19+
* @see https://stackoverflow.com/questions/9602022/chrome-extension-retrieving-global-variable-from-webpage#answer-9636008
20+
*/
21+
1722
import {
1823
CanvasHistory,
1924
DirectoryHandler,
@@ -24,6 +29,9 @@ import {
2429

2530
declare let window: InteractiveCanvasWindow;
2631

32+
/**
33+
* Callback used when iterating through an SDK directory.
34+
*/
2735
type DirectoryIteratorCallback = (
2836
filename: string,
2937
handler: FileHandler
@@ -402,8 +410,6 @@ async function getImgData(blob: Blob): Promise<string> {
402410
});
403411
}
404412

405-
// https://stackoverflow.com/questions/9602022/chrome-extension-retrieving-global-variable-from-webpage#answer-9636008
406-
// Code that runs in the context of the real page, without sandboxing.
407413
window.requestAnimationFrame(() => {
408414
const hasInteractiveCanvas = window.interactiveCanvas !== undefined;
409415

0 commit comments

Comments
 (0)