Skip to content

Commit c2a69c8

Browse files
committed
turned on strictNullChecks for celltags pkg; added it to docs build
1 parent 6e04177 commit c2a69c8

File tree

7 files changed

+38
-59
lines changed

7 files changed

+38
-59
lines changed

packages/celltags-extension/tsconfig.json

+3-18
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,9 @@
11
{
22
"compilerOptions": {
3-
"allowSyntheticDefaultImports": true,
4-
"composite": true,
5-
"declaration": true,
6-
"esModuleInterop": true,
7-
"incremental": true,
8-
"jsx": "react",
9-
"module": "esnext",
10-
"moduleResolution": "node",
11-
"noEmitOnError": true,
12-
"noImplicitAny": true,
13-
"noUnusedLocals": true,
14-
"preserveWatchOutput": true,
15-
"resolveJsonModule": true,
16-
"outDir": "lib",
17-
"rootDir": "src",
183
"strict": true,
19-
"strictNullChecks": false,
20-
"target": "es2017",
21-
"types": ["node"]
4+
5+
"outDir": "lib",
6+
"rootDir": "src"
227
},
238
"include": ["src/*"],
249
"references": [

packages/celltags/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"@jupyterlab/cells": "^2.2.0-alpha.0",
4444
"@jupyterlab/notebook": "^2.2.0-alpha.0",
4545
"@jupyterlab/ui-components": "^2.2.0-alpha.0",
46+
"@lumino/coreutils": "^1.4.2",
4647
"@lumino/widgets": "^1.11.1"
4748
},
4849
"devDependencies": {

packages/celltags/src/addwidget.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class AddWidget extends Widget {
2222
* Create input box with icon and attach to this.node.
2323
*/
2424
buildTag() {
25-
const text = document.createElement('input');
25+
const text = this.input || document.createElement('input');
2626
text.value = 'Add Tag';
2727
text.contentEditable = 'true';
2828
text.className = 'add-tag';
@@ -156,7 +156,7 @@ export class AddWidget extends Widget {
156156
}
157157
}
158158

159-
public parent: TagTool;
159+
public parent: TagTool | null = null;
160160
private editing: boolean;
161-
private input: HTMLInputElement;
161+
private input: HTMLInputElement = document.createElement('input');
162162
}

packages/celltags/src/tool.ts

+21-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ReadonlyPartialJSONArray } from '@lumino/coreutils';
2+
13
import { PanelLayout } from '@lumino/widgets';
24

35
import { NotebookTools, INotebookTracker } from '@jupyterlab/notebook';
@@ -67,6 +69,11 @@ export class TagTool extends NotebookTools.Tool {
6769
*/
6870
addTag(name: string) {
6971
const cell = this.tracker.activeCell;
72+
if (!cell) {
73+
// bail
74+
return;
75+
}
76+
7077
let tags = cell.model.metadata.get('tags') as string[];
7178
const newTags = name.split(/[,\s]+/);
7279
if (tags === undefined) {
@@ -89,6 +96,11 @@ export class TagTool extends NotebookTools.Tool {
8996
*/
9097
removeTag(name: string) {
9198
const cell = this.tracker.activeCell;
99+
if (!cell) {
100+
// bail
101+
return;
102+
}
103+
92104
const tags = cell.model.metadata.get('tags') as string[];
93105
const idx = tags.indexOf(name);
94106
if (idx > -1) {
@@ -120,11 +132,11 @@ export class TagTool extends NotebookTools.Tool {
120132
pullTags() {
121133
const notebook = this.tracker.currentWidget;
122134
if (this.tracker && this.tracker.currentWidget) {
123-
const cells = notebook.model.cells;
135+
const cells = notebook?.model?.cells;
124136
const allTags: string[] = [];
125-
for (let i = 0; i < cells.length; i++) {
126-
const metadata = cells.get(i).metadata;
127-
const tags = metadata.get('tags') as string[];
137+
for (let i = 0; i < (cells?.length || 0); i++) {
138+
const metadata = cells?.get(i).metadata;
139+
const tags = metadata?.get('tags') as ReadonlyPartialJSONArray;
128140
if (tags) {
129141
for (let j = 0; j < tags.length; j++) {
130142
const name = tags[j] as string;
@@ -213,15 +225,15 @@ export class TagTool extends NotebookTools.Tool {
213225
const header = document.createElement('header');
214226
header.textContent = 'Tags in Notebook';
215227
header.className = 'tag-header';
216-
this.parent.node.insertBefore(header, this.node);
228+
this.parent!.node.insertBefore(header, this.node);
217229
this.header = true;
218230
}
219231
if (this.tracker.currentWidget) {
220232
void this.tracker.currentWidget.context.ready.then(() => {
221233
this.refreshTags();
222234
this.loadActiveTags();
223235
});
224-
this.tracker.currentWidget.model.cells.changed.connect(() => {
236+
this.tracker.currentWidget.model!.cells.changed.connect(() => {
225237
this.refreshTags();
226238
this.loadActiveTags();
227239
});
@@ -236,7 +248,7 @@ export class TagTool extends NotebookTools.Tool {
236248
* Handle a change to active cell metadata.
237249
*/
238250
protected onActiveCellMetadataChanged(): void {
239-
const tags = this.tracker.activeCell.model.metadata.get('tags');
251+
const tags = this.tracker.activeCell!.model.metadata.get('tags');
240252
let taglist: string[] = [];
241253
if (tags === undefined) {
242254
return;
@@ -246,10 +258,10 @@ export class TagTool extends NotebookTools.Tool {
246258
} else {
247259
taglist = tags as string[];
248260
}
249-
this.validateTags(this.tracker.activeCell, taglist);
261+
this.validateTags(this.tracker.activeCell!, taglist);
250262
}
251263

252-
public tracker: INotebookTracker = null;
264+
public tracker: INotebookTracker;
253265
private tagList: string[] = [];
254266
private header: boolean = false;
255267
}

packages/celltags/src/widget.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class TagWidget extends Widget {
9595
* Handle `update-request` messages. Check if applied to current active cell.
9696
*/
9797
onUpdateRequest() {
98-
const applied = this.parent.checkApplied(this.name);
98+
const applied = this.parent?.checkApplied(this.name);
9999
if (applied !== this.applied) {
100100
this.toggleApplied();
101101
}
@@ -107,12 +107,12 @@ export class TagWidget extends Widget {
107107
toggleApplied() {
108108
if (this.applied) {
109109
this.removeClass('applied-tag');
110-
(this.node.firstChild.lastChild as HTMLSpanElement).style.display =
110+
(this.node.firstChild?.lastChild as HTMLSpanElement).style.display =
111111
'none';
112112
this.addClass('unapplied-tag');
113113
} else {
114114
this.removeClass('unapplied-tag');
115-
(this.node.firstChild.lastChild as HTMLSpanElement).style.display =
115+
(this.node.firstChild?.lastChild as HTMLSpanElement).style.display =
116116
'inline-block';
117117
this.addClass('applied-tag');
118118
}
@@ -124,9 +124,9 @@ export class TagWidget extends Widget {
124124
*/
125125
private _evtClick() {
126126
if (this.applied) {
127-
this.parent.removeTag(this.name);
127+
this.parent?.removeTag(this.name);
128128
} else {
129-
this.parent.addTag(this.name);
129+
this.parent?.addTag(this.name);
130130
}
131131
this.toggleApplied();
132132
}
@@ -147,5 +147,5 @@ export class TagWidget extends Widget {
147147

148148
public name: string;
149149
private applied: boolean;
150-
public parent: TagTool;
150+
public parent: TagTool | null = null;
151151
}

packages/celltags/tsconfig.json

+3-18
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,9 @@
11
{
22
"compilerOptions": {
3-
"allowSyntheticDefaultImports": true,
4-
"composite": true,
5-
"declaration": true,
6-
"esModuleInterop": true,
7-
"incremental": true,
8-
"jsx": "react",
9-
"module": "esnext",
10-
"moduleResolution": "node",
11-
"noEmitOnError": true,
12-
"noImplicitAny": true,
13-
"noUnusedLocals": true,
14-
"preserveWatchOutput": true,
15-
"resolveJsonModule": true,
16-
"outDir": "lib",
17-
"rootDir": "src",
183
"strict": true,
19-
"strictNullChecks": false,
20-
"target": "es2017",
21-
"types": ["node"]
4+
5+
"outDir": "lib",
6+
"rootDir": "src"
227
},
238
"include": ["src/*"],
249
"references": [

typedoc.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,7 @@ module.exports = {
110110
'**/node_modules/**',
111111
'**/test/**',
112112
'**/tests/**',
113-
'**/testutils/**',
114-
115-
'**/packages/celltags/**'
116-
// '**/packages/logconsole/**'
117-
// '**/packages/settingregistry/**'
113+
'**/testutils/**'
118114
],
119115
excludeNotExported: true,
120116
ignoreCompilerErrors: false,

0 commit comments

Comments
 (0)