ソースを参照

turned on strictNullChecks for celltags pkg; added it to docs build

telamonian 4 年 前
コミット
c2a69c8804

+ 3 - 18
packages/celltags-extension/tsconfig.json

@@ -1,24 +1,9 @@
 {
   "compilerOptions": {
-    "allowSyntheticDefaultImports": true,
-    "composite": true,
-    "declaration": true,
-    "esModuleInterop": true,
-    "incremental": true,
-    "jsx": "react",
-    "module": "esnext",
-    "moduleResolution": "node",
-    "noEmitOnError": true,
-    "noImplicitAny": true,
-    "noUnusedLocals": true,
-    "preserveWatchOutput": true,
-    "resolveJsonModule": true,
-    "outDir": "lib",
-    "rootDir": "src",
     "strict": true,
-    "strictNullChecks": false,
-    "target": "es2017",
-    "types": ["node"]
+
+    "outDir": "lib",
+    "rootDir": "src"
   },
   "include": ["src/*"],
   "references": [

+ 1 - 0
packages/celltags/package.json

@@ -43,6 +43,7 @@
     "@jupyterlab/cells": "^2.2.0-alpha.0",
     "@jupyterlab/notebook": "^2.2.0-alpha.0",
     "@jupyterlab/ui-components": "^2.2.0-alpha.0",
+    "@lumino/coreutils": "^1.4.2",
     "@lumino/widgets": "^1.11.1"
   },
   "devDependencies": {

+ 3 - 3
packages/celltags/src/addwidget.ts

@@ -22,7 +22,7 @@ export class AddWidget extends Widget {
    * Create input box with icon and attach to this.node.
    */
   buildTag() {
-    const text = document.createElement('input');
+    const text = this.input || document.createElement('input');
     text.value = 'Add Tag';
     text.contentEditable = 'true';
     text.className = 'add-tag';
@@ -156,7 +156,7 @@ export class AddWidget extends Widget {
     }
   }
 
-  public parent: TagTool;
+  public parent: TagTool | null = null;
   private editing: boolean;
-  private input: HTMLInputElement;
+  private input: HTMLInputElement = document.createElement('input');
 }

+ 21 - 9
packages/celltags/src/tool.ts

@@ -1,3 +1,5 @@
+import { ReadonlyPartialJSONArray } from '@lumino/coreutils';
+
 import { PanelLayout } from '@lumino/widgets';
 
 import { NotebookTools, INotebookTracker } from '@jupyterlab/notebook';
@@ -67,6 +69,11 @@ export class TagTool extends NotebookTools.Tool {
    */
   addTag(name: string) {
     const cell = this.tracker.activeCell;
+    if (!cell) {
+      // bail
+      return;
+    }
+
     let tags = cell.model.metadata.get('tags') as string[];
     const newTags = name.split(/[,\s]+/);
     if (tags === undefined) {
@@ -89,6 +96,11 @@ export class TagTool extends NotebookTools.Tool {
    */
   removeTag(name: string) {
     const cell = this.tracker.activeCell;
+    if (!cell) {
+      // bail
+      return;
+    }
+
     const tags = cell.model.metadata.get('tags') as string[];
     const idx = tags.indexOf(name);
     if (idx > -1) {
@@ -120,11 +132,11 @@ export class TagTool extends NotebookTools.Tool {
   pullTags() {
     const notebook = this.tracker.currentWidget;
     if (this.tracker && this.tracker.currentWidget) {
-      const cells = notebook.model.cells;
+      const cells = notebook?.model?.cells;
       const allTags: string[] = [];
-      for (let i = 0; i < cells.length; i++) {
-        const metadata = cells.get(i).metadata;
-        const tags = metadata.get('tags') as string[];
+      for (let i = 0; i < (cells?.length || 0); i++) {
+        const metadata = cells?.get(i).metadata;
+        const tags = metadata?.get('tags') as ReadonlyPartialJSONArray;
         if (tags) {
           for (let j = 0; j < tags.length; j++) {
             const name = tags[j] as string;
@@ -213,7 +225,7 @@ export class TagTool extends NotebookTools.Tool {
       const header = document.createElement('header');
       header.textContent = 'Tags in Notebook';
       header.className = 'tag-header';
-      this.parent.node.insertBefore(header, this.node);
+      this.parent!.node.insertBefore(header, this.node);
       this.header = true;
     }
     if (this.tracker.currentWidget) {
@@ -221,7 +233,7 @@ export class TagTool extends NotebookTools.Tool {
         this.refreshTags();
         this.loadActiveTags();
       });
-      this.tracker.currentWidget.model.cells.changed.connect(() => {
+      this.tracker.currentWidget.model!.cells.changed.connect(() => {
         this.refreshTags();
         this.loadActiveTags();
       });
@@ -236,7 +248,7 @@ export class TagTool extends NotebookTools.Tool {
    * Handle a change to active cell metadata.
    */
   protected onActiveCellMetadataChanged(): void {
-    const tags = this.tracker.activeCell.model.metadata.get('tags');
+    const tags = this.tracker.activeCell!.model.metadata.get('tags');
     let taglist: string[] = [];
     if (tags === undefined) {
       return;
@@ -246,10 +258,10 @@ export class TagTool extends NotebookTools.Tool {
     } else {
       taglist = tags as string[];
     }
-    this.validateTags(this.tracker.activeCell, taglist);
+    this.validateTags(this.tracker.activeCell!, taglist);
   }
 
-  public tracker: INotebookTracker = null;
+  public tracker: INotebookTracker;
   private tagList: string[] = [];
   private header: boolean = false;
 }

+ 6 - 6
packages/celltags/src/widget.ts

@@ -95,7 +95,7 @@ export class TagWidget extends Widget {
    * Handle `update-request` messages. Check if applied to current active cell.
    */
   onUpdateRequest() {
-    const applied = this.parent.checkApplied(this.name);
+    const applied = this.parent?.checkApplied(this.name);
     if (applied !== this.applied) {
       this.toggleApplied();
     }
@@ -107,12 +107,12 @@ export class TagWidget extends Widget {
   toggleApplied() {
     if (this.applied) {
       this.removeClass('applied-tag');
-      (this.node.firstChild.lastChild as HTMLSpanElement).style.display =
+      (this.node.firstChild?.lastChild as HTMLSpanElement).style.display =
         'none';
       this.addClass('unapplied-tag');
     } else {
       this.removeClass('unapplied-tag');
-      (this.node.firstChild.lastChild as HTMLSpanElement).style.display =
+      (this.node.firstChild?.lastChild as HTMLSpanElement).style.display =
         'inline-block';
       this.addClass('applied-tag');
     }
@@ -124,9 +124,9 @@ export class TagWidget extends Widget {
    */
   private _evtClick() {
     if (this.applied) {
-      this.parent.removeTag(this.name);
+      this.parent?.removeTag(this.name);
     } else {
-      this.parent.addTag(this.name);
+      this.parent?.addTag(this.name);
     }
     this.toggleApplied();
   }
@@ -147,5 +147,5 @@ export class TagWidget extends Widget {
 
   public name: string;
   private applied: boolean;
-  public parent: TagTool;
+  public parent: TagTool | null = null;
 }

+ 3 - 18
packages/celltags/tsconfig.json

@@ -1,24 +1,9 @@
 {
   "compilerOptions": {
-    "allowSyntheticDefaultImports": true,
-    "composite": true,
-    "declaration": true,
-    "esModuleInterop": true,
-    "incremental": true,
-    "jsx": "react",
-    "module": "esnext",
-    "moduleResolution": "node",
-    "noEmitOnError": true,
-    "noImplicitAny": true,
-    "noUnusedLocals": true,
-    "preserveWatchOutput": true,
-    "resolveJsonModule": true,
-    "outDir": "lib",
-    "rootDir": "src",
     "strict": true,
-    "strictNullChecks": false,
-    "target": "es2017",
-    "types": ["node"]
+
+    "outDir": "lib",
+    "rootDir": "src"
   },
   "include": ["src/*"],
   "references": [

+ 1 - 5
typedoc.js

@@ -110,11 +110,7 @@ module.exports = {
     '**/node_modules/**',
     '**/test/**',
     '**/tests/**',
-    '**/testutils/**',
-
-    '**/packages/celltags/**'
-    // '**/packages/logconsole/**'
-    // '**/packages/settingregistry/**'
+    '**/testutils/**'
   ],
   excludeNotExported: true,
   ignoreCompilerErrors: false,