You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@annotator.apache.org by ge...@apache.org on 2021/06/05 17:14:12 UTC

[incubator-annotator] branch master updated (c28d5d3 -> 08575e9)

This is an automated email from the ASF dual-hosted git repository.

gerben pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-annotator.git.


    from c28d5d3  Merge branch 'allow-node-as-scope' (PR #110)
     new 65cafd1  Run linter
     new 08575e9  Declare types for optimal-select dependency

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .gitignore                                    |  1 +
 packages/dom/@types/optimal-select/index.d.ts |  9 +++++++++
 packages/dom/src/owner-document.ts            |  6 ++----
 packages/dom/src/range/match.ts               |  5 +++--
 packages/dom/src/text-position/describe.ts    |  4 ++--
 packages/dom/src/text-quote/describe.ts       |  2 +-
 packages/dom/src/to-range.ts                  |  4 ++--
 packages/dom/test/css/describe.test.ts        | 21 ++++++++++++---------
 packages/dom/test/css/match-cases.ts          | 13 +++----------
 packages/dom/test/css/match.test.ts           |  2 +-
 packages/dom/tsconfig.json                    |  2 +-
 11 files changed, 37 insertions(+), 32 deletions(-)
 create mode 100644 packages/dom/@types/optimal-select/index.d.ts

[incubator-annotator] 02/02: Declare types for optimal-select dependency

Posted by ge...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gerben pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-annotator.git

commit 08575e97aa3e1a9286f1cf17237fd5fe870a85bf
Author: Gerben <ge...@treora.com>
AuthorDate: Sat Jun 5 18:57:34 2021 +0200

    Declare types for optimal-select dependency
    
    The linter does not seem to pick it up however..
---
 .gitignore                                    | 1 +
 packages/dom/@types/optimal-select/index.d.ts | 9 +++++++++
 packages/dom/tsconfig.json                    | 2 +-
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/.gitignore b/.gitignore
index 0fd2b1a..f28d081 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
 *.d.ts
+!/packages/**/@types/**/*.d.ts
 *.d.ts.map
 .nyc_output
 coverage
diff --git a/packages/dom/@types/optimal-select/index.d.ts b/packages/dom/@types/optimal-select/index.d.ts
new file mode 100644
index 0000000..90eb3f4
--- /dev/null
+++ b/packages/dom/@types/optimal-select/index.d.ts
@@ -0,0 +1,9 @@
+// Partial declaration, just to cover the pieces we need.
+declare module 'optimal-select' {
+  export default function optimalSelect(
+    element: Element,
+    options: {
+      root: Node,
+    },
+  ): string;
+}
diff --git a/packages/dom/tsconfig.json b/packages/dom/tsconfig.json
index 02e0fcf..e26d55e 100644
--- a/packages/dom/tsconfig.json
+++ b/packages/dom/tsconfig.json
@@ -1,6 +1,6 @@
 {
   "extends": "../../tsconfig.base.json",
-  "include": ["src"],
+  "include": ["src", "./@types"],
   "compilerOptions": {
     "outDir": "lib",
     "rootDir": "src"

[incubator-annotator] 01/02: Run linter

Posted by ge...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gerben pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-annotator.git

commit 65cafd1a460e3f1aad9df99b6f35a44456d4067e
Author: Gerben <ge...@treora.com>
AuthorDate: Sat Jun 5 18:30:03 2021 +0200

    Run linter
---
 packages/dom/src/owner-document.ts         |  6 ++----
 packages/dom/src/range/match.ts            |  5 +++--
 packages/dom/src/text-position/describe.ts |  4 ++--
 packages/dom/src/text-quote/describe.ts    |  2 +-
 packages/dom/src/to-range.ts               |  4 ++--
 packages/dom/test/css/describe.test.ts     | 21 ++++++++++++---------
 packages/dom/test/css/match-cases.ts       | 13 +++----------
 packages/dom/test/css/match.test.ts        |  2 +-
 8 files changed, 26 insertions(+), 31 deletions(-)

diff --git a/packages/dom/src/owner-document.ts b/packages/dom/src/owner-document.ts
index fe7818a..102a7de 100644
--- a/packages/dom/src/owner-document.ts
+++ b/packages/dom/src/owner-document.ts
@@ -24,13 +24,11 @@
  * @param nodeOrRange the node or range for which to get the owner document.
  */
 export function ownerDocument(nodeOrRange: Node | Range): Document {
-  const node = isRange(nodeOrRange)
-    ? nodeOrRange.startContainer
-    : nodeOrRange;
+  const node = isRange(nodeOrRange) ? nodeOrRange.startContainer : nodeOrRange;
   // node.ownerDocument is null iff node is itself a Document.
   return node.ownerDocument ?? (node as Document);
 }
 
 function isRange(nodeOrRange: Node | Range): nodeOrRange is Range {
-  return ('startContainer' in nodeOrRange);
+  return 'startContainer' in nodeOrRange;
 }
diff --git a/packages/dom/src/range/match.ts b/packages/dom/src/range/match.ts
index 6ffece3..d6891c6 100644
--- a/packages/dom/src/range/match.ts
+++ b/packages/dom/src/range/match.ts
@@ -93,8 +93,9 @@ import { cartesian } from './cartesian';
  * @public
  */
 export function makeCreateRangeSelectorMatcher(
-  createMatcher: <T extends Selector, TMatch extends Node | Range>(selector: T)
-    => Matcher<Node | Range, TMatch>,
+  createMatcher: <T extends Selector, TMatch extends Node | Range>(
+    selector: T,
+  ) => Matcher<Node | Range, TMatch>,
 ): (selector: RangeSelector) => Matcher<Node | Range, Range> {
   return function createRangeSelectorMatcher(selector) {
     const startMatcher = createMatcher(selector.startSelector);
diff --git a/packages/dom/src/text-position/describe.ts b/packages/dom/src/text-position/describe.ts
index 6e9566b..ce33312 100644
--- a/packages/dom/src/text-position/describe.ts
+++ b/packages/dom/src/text-position/describe.ts
@@ -21,8 +21,8 @@
 import type { TextPositionSelector } from '@apache-annotator/selector';
 import { describeTextPosition as abstractDescribeTextPosition } from '@apache-annotator/selector';
 import { ownerDocument } from '../owner-document';
-import { toRange } from '../to-range';
 import { TextNodeChunker } from '../text-node-chunker';
+import { toRange } from '../to-range';
 
 /**
  * Returns a {@link TextPositionSelector} that points at the target text within
@@ -59,7 +59,7 @@ export async function describeTextPosition(
   range: Range,
   scope?: Node | Range,
 ): Promise<TextPositionSelector> {
-  scope = toRange(scope ?? ownerDocument(range))
+  scope = toRange(scope ?? ownerDocument(range));
 
   const textChunks = new TextNodeChunker(scope);
   if (textChunks.currentChunk === null)
diff --git a/packages/dom/src/text-quote/describe.ts b/packages/dom/src/text-quote/describe.ts
index f5be4b9..727fa40 100644
--- a/packages/dom/src/text-quote/describe.ts
+++ b/packages/dom/src/text-quote/describe.ts
@@ -24,8 +24,8 @@ import type {
 } from '@apache-annotator/selector';
 import { describeTextQuote as abstractDescribeTextQuote } from '@apache-annotator/selector';
 import { ownerDocument } from '../owner-document';
-import { toRange } from '../to-range';
 import { TextNodeChunker } from '../text-node-chunker';
+import { toRange } from '../to-range';
 
 /**
  * Returns a {@link TextQuoteSelector} that unambiguously describes the given
diff --git a/packages/dom/src/to-range.ts b/packages/dom/src/to-range.ts
index fd62543..d4cc3d5 100644
--- a/packages/dom/src/to-range.ts
+++ b/packages/dom/src/to-range.ts
@@ -18,7 +18,7 @@
  * under the License.
  */
 
-import { ownerDocument } from "./owner-document";
+import { ownerDocument } from './owner-document';
 
 /**
  * Returns a range that exactly selects the contents of the given node.
@@ -41,5 +41,5 @@ export function toRange(nodeOrRange: Node | Range): Range {
 }
 
 function isRange(nodeOrRange: Node | Range): nodeOrRange is Range {
-  return ('startContainer' in nodeOrRange);
+  return 'startContainer' in nodeOrRange;
 }
diff --git a/packages/dom/test/css/describe.test.ts b/packages/dom/test/css/describe.test.ts
index 17d1ce9..711c9ce 100644
--- a/packages/dom/test/css/describe.test.ts
+++ b/packages/dom/test/css/describe.test.ts
@@ -20,8 +20,8 @@
 
 import { assert } from 'chai';
 import { describeCss } from '../../src/css';
-import { testCases } from './match-cases';
 import { evaluateXPath } from '../utils';
+import { testCases } from './match-cases';
 
 const domParser = new DOMParser();
 
@@ -32,21 +32,24 @@ describe('describeCss', () => {
     )) {
       for (let i = 0; i < expected.length; i++) {
         const elementXPath = expected[i];
-        it(`case: '${name}' (${i+1}/${expected.length})`, async () => {
+        it(`case: '${name}' (${i + 1}/${expected.length})`, async () => {
           const doc = domParser.parseFromString(html, 'text/html');
           const element = evaluateXPath(doc, elementXPath) as HTMLElement;
           const scopeElement = scopeXPath
-            ? evaluateXPath(doc, scopeXPath) as HTMLElement
+            ? (evaluateXPath(doc, scopeXPath) as HTMLElement)
             : undefined;
-          const cssSelector = await describeCss(
-            element,
-            scopeElement,
-          );
+          const cssSelector = await describeCss(element, scopeElement);
 
           // We do not require a specific value for the selector, just
           // that it uniquely matches the same element again.
-          const matchingElements = (scopeElement ?? doc).querySelectorAll(cssSelector.value);
-          assert.equal(matchingElements.length, 1, 'Expected a selector with a single match');
+          const matchingElements = (scopeElement ?? doc).querySelectorAll(
+            cssSelector.value,
+          );
+          assert.equal(
+            matchingElements.length,
+            1,
+            'Expected a selector with a single match',
+          );
           assert.equal(matchingElements[0], element);
         });
       }
diff --git a/packages/dom/test/css/match-cases.ts b/packages/dom/test/css/match-cases.ts
index 26fbe03..1cf28b9 100644
--- a/packages/dom/test/css/match-cases.ts
+++ b/packages/dom/test/css/match-cases.ts
@@ -28,7 +28,7 @@ export const testCases: {
     expected: string[];
   };
 } = {
-  'simple': {
+  simple: {
     html: '<b>lorem <i>ipsum</i> dolor <i>amet</i> yada <i>yada</i></b>',
     selector: {
       type: 'CssSelector',
@@ -42,11 +42,7 @@ export const testCases: {
       type: 'CssSelector',
       value: 'i',
     },
-    expected: [
-      '//b/i[1]',
-      '//b/i[2]',
-      '//b/i[3]',
-    ],
+    expected: ['//b/i[1]', '//b/i[2]', '//b/i[3]'],
   },
   'with scope': {
     html: '<b>lorem <i>ipsum</i> dolor <u><i>amet</i> yada <i>yada</i></u></b>',
@@ -55,9 +51,6 @@ export const testCases: {
       value: 'i',
     },
     scopeXPath: '//u',
-    expected: [
-      '//u/i[1]',
-      '//u/i[2]',
-    ],
+    expected: ['//u/i[1]', '//u/i[2]'],
   },
 };
diff --git a/packages/dom/test/css/match.test.ts b/packages/dom/test/css/match.test.ts
index 2c5d682..ad39b42 100644
--- a/packages/dom/test/css/match.test.ts
+++ b/packages/dom/test/css/match.test.ts
@@ -21,8 +21,8 @@
 import { assert } from 'chai';
 import type { CssSelector } from '@apache-annotator/selector';
 import { createCssSelectorMatcher } from '../../src/css';
-import { testCases } from './match-cases';
 import { evaluateXPath } from '../utils';
+import { testCases } from './match-cases';
 
 const domParser = new DOMParser();