Browse Source

Refactor document search into a normal package and an extension.

Jason Grout 6 năm trước cách đây
mục cha
commit
8df4c864fc

+ 1 - 0
packages/csvviewer-extension/package.json

@@ -34,6 +34,7 @@
     "@jupyterlab/apputils": "^0.19.1",
     "@jupyterlab/csvviewer": "^0.19.1",
     "@jupyterlab/docregistry": "^0.19.1",
+    "@jupyterlab/documentsearch": "^0.7.1",
     "@jupyterlab/documentsearch-extension": "^0.19.1",
     "@jupyterlab/mainmenu": "^0.8.1",
     "@phosphor/datagrid": "^0.1.6",

+ 1 - 4
packages/csvviewer-extension/src/searchprovider.ts

@@ -1,9 +1,6 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
-import {
-  ISearchProvider,
-  ISearchMatch
-} from '@jupyterlab/documentsearch-extension';
+import { ISearchProvider, ISearchMatch } from '@jupyterlab/documentsearch';
 import { CSVViewer } from '@jupyterlab/csvviewer';
 import { IDocumentWidget, DocumentWidget } from '@jupyterlab/docregistry';
 import { Signal, ISignal } from '@phosphor/signaling';

+ 3 - 0
packages/csvviewer-extension/tsconfig.json

@@ -18,6 +18,9 @@
     {
       "path": "../docregistry"
     },
+    {
+      "path": "../documentsearch"
+    },
     {
       "path": "../documentsearch-extension"
     },

+ 1 - 0
packages/documentsearch-extension/package.json

@@ -34,6 +34,7 @@
     "@jupyterlab/codeeditor": "^0.19.1",
     "@jupyterlab/codemirror": "^0.19.1",
     "@jupyterlab/docregistry": "^0.19.1",
+    "@jupyterlab/documentsearch": "^0.7.1",
     "@jupyterlab/mainmenu": "^0.8.1",
     "@jupyterlab/notebook": "^0.19.2",
     "@phosphor/coreutils": "^1.3.0",

+ 4 - 146
packages/documentsearch-extension/src/index.ts

@@ -1,12 +1,12 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
-import '../style/index.css';
+import '@jupyterlab/documentsearch/style/index.css';
 
 import {
   SearchProviderRegistry,
   ISearchProviderRegistry
-} from './searchproviderregistry';
-import { SearchInstance } from './searchinstance';
+} from '@jupyterlab/documentsearch';
+import { SearchInstance } from '@jupyterlab/documentsearch';
 
 import {
   JupyterFrontEnd,
@@ -17,149 +17,7 @@ import { ICommandPalette } from '@jupyterlab/apputils';
 
 import { IMainMenu } from '@jupyterlab/mainmenu';
 
-import { ISignal } from '@phosphor/signaling';
-
-export { ISearchProviderRegistry } from './searchproviderregistry';
-
-export interface ISearchMatch {
-  /**
-   * Text of the exact match itself
-   */
-  readonly text: string;
-
-  /**
-   * Fragment containing match
-   */
-  readonly fragment: string;
-
-  /**
-   * Line number of match
-   */
-  line: number;
-
-  /**
-   * Column location of match
-   */
-  column: number;
-
-  /**
-   * Index among the other matches
-   */
-  index: number;
-}
-
-/**
- * This interface is meant to enforce that SearchProviders implement the static
- * canSearchOn function.
- */
-export interface ISearchProviderConstructor {
-  new (): ISearchProvider;
-  /**
-   * Report whether or not this provider has the ability to search on the given object
-   */
-  canSearchOn(domain: any): boolean;
-}
-
-export interface ISearchProvider {
-  /**
-   * Initialize the search using the provided options.  Should update the UI
-   * to highlight all matches and "select" whatever the first match should be.
-   *
-   * @param query A RegExp to be use to perform the search
-   * @param searchTarget The widget to be searched
-   *
-   * @returns A promise that resolves with a list of all matches
-   */
-  startQuery(query: RegExp, searchTarget: any): Promise<ISearchMatch[]>;
-
-  /**
-   * Clears state of a search provider to prepare for startQuery to be called
-   * in order to start a new query or refresh an existing one.
-   *
-   * @returns A promise that resolves when the search provider is ready to
-   * begin a new search.
-   */
-  endQuery(): Promise<void>;
-
-  /**
-   * Resets UI state as it was before the search process began.  Cleans up and
-   * disposes of all internal state.
-   *
-   * @returns A promise that resolves when all state has been cleaned up.
-   */
-  endSearch(): Promise<void>;
-
-  /**
-   * Move the current match indicator to the next match.
-   *
-   * @returns A promise that resolves once the action has completed.
-   */
-  highlightNext(): Promise<ISearchMatch | undefined>;
-
-  /**
-   * Move the current match indicator to the previous match.
-   *
-   * @returns A promise that resolves once the action has completed.
-   */
-  highlightPrevious(): Promise<ISearchMatch | undefined>;
-
-  /**
-   * The same list of matches provided by the startQuery promise resoluton
-   */
-  readonly matches: ISearchMatch[];
-
-  /**
-   * Signal indicating that something in the search has changed, so the UI should update
-   */
-  readonly changed: ISignal<ISearchProvider, void>;
-
-  /**
-   * The current index of the selected match.
-   */
-  readonly currentMatchIndex: number | null;
-}
-
-export interface IDisplayState {
-  /**
-   * The index of the currently selected match
-   */
-  currentIndex: number;
-
-  /**
-   * The total number of matches found in the document
-   */
-  totalMatches: number;
-
-  /**
-   * Should the search be case sensitive?
-   */
-  caseSensitive: boolean;
-
-  /**
-   * Should the search string be treated as a RegExp?
-   */
-  useRegex: boolean;
-
-  /**
-   * The text in the entry
-   */
-  inputText: string;
-
-  /**
-   * The query constructed from the text and the case/regex flags
-   */
-  query: RegExp;
-
-  /**
-   * An error message (used for bad regex syntax)
-   */
-  errorMessage: string;
-
-  /**
-   * Should the focus forced into the input on the next render?
-   */
-  forceFocus: boolean;
-}
+export { ISearchProviderRegistry } from '@jupyterlab/documentsearch';
 
 /**
  * Initialization data for the document-search extension.

+ 0 - 4
packages/documentsearch-extension/src/searchproviders.ts

@@ -1,4 +0,0 @@
-// Copyright (c) Jupyter Development Team.
-// Distributed under the terms of the Modified BSD License.
-export * from './providers/notebooksearchprovider';
-export * from './providers/codemirrorsearchprovider';

+ 3 - 0
packages/documentsearch-extension/tsconfig.json

@@ -24,6 +24,9 @@
     {
       "path": "../docregistry"
     },
+    {
+      "path": "../documentsearch"
+    },
     {
       "path": "../mainmenu"
     },

+ 13 - 0
packages/documentsearch/package.json

@@ -27,6 +27,19 @@
     "prepublishOnly": "npm run build",
     "watch": "tsc -w --listEmittedFiles"
   },
+  "dependencies": {
+    "@jupyterlab/apputils": "^0.19.1",
+    "@jupyterlab/cells": "^0.19.1",
+    "@jupyterlab/codeeditor": "^0.19.1",
+    "@jupyterlab/codemirror": "^0.19.1",
+    "@jupyterlab/notebook": "^0.19.2",
+    "@phosphor/coreutils": "^1.3.0",
+    "@phosphor/disposable": "^1.1.2",
+    "@phosphor/signaling": "^1.2.2",
+    "@phosphor/widgets": "^1.6.0",
+    "codemirror": "~5.42.0",
+    "react": "~16.4.2"
+  },
   "devDependencies": {
     "rimraf": "~2.6.2",
     "typescript": "~3.3.1"

+ 6 - 4
packages/documentsearch/src/index.ts

@@ -1,4 +1,6 @@
-/*-----------------------------------------------------------------------------
-| Copyright (c) Jupyter Development Team.
-| Distributed under the terms of the Modified BSD License.
-|----------------------------------------------------------------------------*/
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+
+export * from './searchproviderregistry';
+export * from './searchinstance';
+export * from './interfaces';

+ 144 - 0
packages/documentsearch/src/interfaces.ts

@@ -0,0 +1,144 @@
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+
+import { ISignal } from '@phosphor/signaling';
+
+export interface IDisplayState {
+  /**
+   * The index of the currently selected match
+   */
+  currentIndex: number;
+
+  /**
+   * The total number of matches found in the document
+   */
+  totalMatches: number;
+
+  /**
+   * Should the search be case sensitive?
+   */
+  caseSensitive: boolean;
+
+  /**
+   * Should the search string be treated as a RegExp?
+   */
+  useRegex: boolean;
+
+  /**
+   * The text in the entry
+   */
+  inputText: string;
+
+  /**
+   * The query constructed from the text and the case/regex flags
+   */
+  query: RegExp;
+
+  /**
+   * An error message (used for bad regex syntax)
+   */
+  errorMessage: string;
+
+  /**
+   * Should the focus forced into the input on the next render?
+   */
+  forceFocus: boolean;
+}
+
+export interface ISearchMatch {
+  /**
+   * Text of the exact match itself
+   */
+  readonly text: string;
+
+  /**
+   * Fragment containing match
+   */
+  readonly fragment: string;
+
+  /**
+   * Line number of match
+   */
+  line: number;
+
+  /**
+   * Column location of match
+   */
+  column: number;
+
+  /**
+   * Index among the other matches
+   */
+  index: number;
+}
+
+/**
+ * This interface is meant to enforce that SearchProviders implement the static
+ * canSearchOn function.
+ */
+export interface ISearchProviderConstructor {
+  new (): ISearchProvider;
+  /**
+   * Report whether or not this provider has the ability to search on the given object
+   */
+  canSearchOn(domain: any): boolean;
+}
+
+export interface ISearchProvider {
+  /**
+   * Initialize the search using the provided options.  Should update the UI
+   * to highlight all matches and "select" whatever the first match should be.
+   *
+   * @param query A RegExp to be use to perform the search
+   * @param searchTarget The widget to be searched
+   *
+   * @returns A promise that resolves with a list of all matches
+   */
+  startQuery(query: RegExp, searchTarget: any): Promise<ISearchMatch[]>;
+
+  /**
+   * Clears state of a search provider to prepare for startQuery to be called
+   * in order to start a new query or refresh an existing one.
+   *
+   * @returns A promise that resolves when the search provider is ready to
+   * begin a new search.
+   */
+  endQuery(): Promise<void>;
+
+  /**
+   * Resets UI state as it was before the search process began.  Cleans up and
+   * disposes of all internal state.
+   *
+   * @returns A promise that resolves when all state has been cleaned up.
+   */
+  endSearch(): Promise<void>;
+
+  /**
+   * Move the current match indicator to the next match.
+   *
+   * @returns A promise that resolves once the action has completed.
+   */
+  highlightNext(): Promise<ISearchMatch | undefined>;
+
+  /**
+   * Move the current match indicator to the previous match.
+   *
+   * @returns A promise that resolves once the action has completed.
+   */
+  highlightPrevious(): Promise<ISearchMatch | undefined>;
+
+  /**
+   * The same list of matches provided by the startQuery promise resoluton
+   */
+  readonly matches: ISearchMatch[];
+
+  /**
+   * Signal indicating that something in the search has changed, so the UI should update
+   */
+  readonly changed: ISignal<ISearchProvider, void>;
+
+  /**
+   * The current index of the selected match.
+   */
+  readonly currentMatchIndex: number | null;
+}

+ 0 - 0
packages/documentsearch-extension/src/providers/codemirrorsearchprovider.ts → packages/documentsearch/src/providers/codemirrorsearchprovider.ts


+ 0 - 0
packages/documentsearch-extension/src/providers/notebooksearchprovider.ts → packages/documentsearch/src/providers/notebooksearchprovider.ts


+ 1 - 1
packages/documentsearch-extension/src/searchinstance.ts → packages/documentsearch/src/searchinstance.ts

@@ -7,8 +7,8 @@ import { createSearchOverlay } from './searchoverlay';
 import { MainAreaWidget } from '@jupyterlab/apputils';
 
 import { Widget } from '@phosphor/widgets';
-import { ISignal, Signal } from '@phosphor/signaling';
 import { IDisposable } from '@phosphor/disposable';
+import { ISignal, Signal } from '@phosphor/signaling';
 
 /**
  * Represents a search on a single widget.

+ 0 - 0
packages/documentsearch-extension/src/searchoverlay.tsx → packages/documentsearch/src/searchoverlay.tsx


+ 2 - 4
packages/documentsearch-extension/src/searchproviderregistry.ts → packages/documentsearch/src/searchproviderregistry.ts

@@ -1,10 +1,8 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 import { ISearchProvider, ISearchProviderConstructor } from './index';
-import {
-  CodeMirrorSearchProvider,
-  NotebookSearchProvider
-} from './searchproviders';
+import { CodeMirrorSearchProvider } from './providers/codemirrorsearchprovider';
+import { NotebookSearchProvider } from './providers/notebooksearchprovider';
 
 const DEFAULT_NOTEBOOK_SEARCH_PROVIDER = 'jl-defaultNotebookSearchProvider';
 const DEFAULT_CODEMIRROR_SEARCH_PROVIDER = 'jl-defaultCodeMirrorSearchProvider';

+ 0 - 0
packages/documentsearch-extension/style/index.css → packages/documentsearch/style/index.css


+ 18 - 1
packages/documentsearch/tsconfig.json

@@ -4,5 +4,22 @@
     "outDir": "lib",
     "rootDir": "src"
   },
-  "include": ["src/*"]
+  "include": ["src/**/*"],
+  "references": [
+    {
+      "path": "../apputils"
+    },
+    {
+      "path": "../cells"
+    },
+    {
+      "path": "../codeeditor"
+    },
+    {
+      "path": "../codemirror"
+    },
+    {
+      "path": "../notebook"
+    }
+  ]
 }