Commit c76894f8 authored by Robert Knight's avatar Robert Knight

Convert additional src/annotator/ modules to ES modules

This converts all modules except those which:

 1) Are written in CoffeeScript OR

 2) Are written in JS AND have a default export AND are imported from a
    module written in CoffeeScript.

    This last case is a bit more complex to handle and needs a little
    investigation or a decision to punt it to after the CoffeeScript =>
    JS conversion is complete
parent 8bc370c8
const classnames = require('classnames'); import classnames from 'classnames';
const template = require('./adder.html'); import template from './adder.html';
const ANNOTATE_BTN_SELECTOR = '.js-annotate-btn'; const ANNOTATE_BTN_SELECTOR = '.js-annotate-btn';
const HIGHLIGHT_BTN_SELECTOR = '.js-highlight-btn'; const HIGHLIGHT_BTN_SELECTOR = '.js-highlight-btn';
...@@ -120,7 +120,7 @@ function createAdderDOM(container) { ...@@ -120,7 +120,7 @@ function createAdderDOM(container) {
* Annotation 'adder' toolbar which appears next to the selection * Annotation 'adder' toolbar which appears next to the selection
* and provides controls for the user to create new annotations. * and provides controls for the user to create new annotations.
*/ */
class Adder { export class Adder {
/** /**
* Construct the toolbar and populate the UI. * Construct the toolbar and populate the UI.
* *
...@@ -288,9 +288,4 @@ class Adder { ...@@ -288,9 +288,4 @@ class Adder {
} }
} }
module.exports = { export { ARROW_POINTING_DOWN, ARROW_POINTING_UP };
ARROW_POINTING_DOWN: ARROW_POINTING_DOWN,
ARROW_POINTING_UP: ARROW_POINTING_UP,
Adder: Adder,
};
const Sidebar = require('./sidebar'); import Sidebar from './sidebar';
const DEFAULT_CONFIG = { const DEFAULT_CONFIG = {
TextSelection: {}, TextSelection: {},
...@@ -12,10 +12,8 @@ const DEFAULT_CONFIG = { ...@@ -12,10 +12,8 @@ const DEFAULT_CONFIG = {
}, },
}; };
class PdfSidebar extends Sidebar { export default class PdfSidebar extends Sidebar {
constructor(element, config) { constructor(element, config) {
super(element, Object.assign({}, DEFAULT_CONFIG, config)); super(element, Object.assign({}, DEFAULT_CONFIG, config));
} }
} }
module.exports = PdfSidebar;
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Returns true if the start point of a selection occurs after the end point, * Returns true if the start point of a selection occurs after the end point,
* in document order. * in document order.
*/ */
function isSelectionBackwards(selection) { export function isSelectionBackwards(selection) {
if (selection.focusNode === selection.anchorNode) { if (selection.focusNode === selection.anchorNode) {
return selection.focusOffset < selection.anchorOffset; return selection.focusOffset < selection.anchorOffset;
} }
...@@ -20,7 +20,7 @@ function isSelectionBackwards(selection) { ...@@ -20,7 +20,7 @@ function isSelectionBackwards(selection) {
* @param {Range} range * @param {Range} range
* @param {Node} node * @param {Node} node
*/ */
function isNodeInRange(range, node) { export function isNodeInRange(range, node) {
if (node === range.startContainer || node === range.endContainer) { if (node === range.startContainer || node === range.endContainer) {
return true; return true;
} }
...@@ -69,7 +69,7 @@ function forEachNodeInRange(range, callback) { ...@@ -69,7 +69,7 @@ function forEachNodeInRange(range, callback) {
* @param {Range} range * @param {Range} range
* @return {Array<Rect>} Array of bounding rects in viewport coordinates. * @return {Array<Rect>} Array of bounding rects in viewport coordinates.
*/ */
function getTextBoundingBoxes(range) { export function getTextBoundingBoxes(range) {
const whitespaceOnly = /^\s*$/; const whitespaceOnly = /^\s*$/;
const textNodes = []; const textNodes = [];
forEachNodeInRange(range, function(node) { forEachNodeInRange(range, function(node) {
...@@ -114,7 +114,7 @@ function getTextBoundingBoxes(range) { ...@@ -114,7 +114,7 @@ function getTextBoundingBoxes(range) {
* @param {Selection} selection * @param {Selection} selection
* @return {Rect|null} * @return {Rect|null}
*/ */
function selectionFocusRect(selection) { export function selectionFocusRect(selection) {
if (selection.isCollapsed) { if (selection.isCollapsed) {
return null; return null;
} }
...@@ -129,10 +129,3 @@ function selectionFocusRect(selection) { ...@@ -129,10 +129,3 @@ function selectionFocusRect(selection) {
return textBoxes[textBoxes.length - 1]; return textBoxes[textBoxes.length - 1];
} }
} }
module.exports = {
getTextBoundingBoxes: getTextBoundingBoxes,
isNodeInRange: isNodeInRange,
isSelectionBackwards: isSelectionBackwards,
selectionFocusRect: selectionFocusRect,
};
// Tests that the expected parts of the page are highlighted when annotations // Tests that the expected parts of the page are highlighted when annotations
// with various combinations of selector are anchored. // with various combinations of selector are anchored.
const Guest = require('../../guest'); import Guest from '../../guest';
function quoteSelector(quote) { function quoteSelector(quote) {
return { return {
......
const { isLoaded } = require('../../util/frame-util'); import { DEBOUNCE_WAIT } from '../../frame-observer';
import CrossFrame from '../../plugin/cross-frame';
const FRAME_DEBOUNCE_WAIT = require('../../frame-observer').DEBOUNCE_WAIT + 10; import { $imports } from '../../plugin/cross-frame';
const CrossFrame = require('../../plugin/cross-frame'); import { isLoaded } from '../../util/frame-util';
const { $imports } = require('../../plugin/cross-frame');
describe('CrossFrame multi-frame scenario', function() { describe('CrossFrame multi-frame scenario', function() {
let fakeAnnotationSync; let fakeAnnotationSync;
...@@ -16,7 +15,8 @@ describe('CrossFrame multi-frame scenario', function() { ...@@ -16,7 +15,8 @@ describe('CrossFrame multi-frame scenario', function() {
const sandbox = sinon.createSandbox(); const sandbox = sinon.createSandbox();
const waitForFrameObserver = function(cb) { const waitForFrameObserver = function(cb) {
return setTimeout(cb, FRAME_DEBOUNCE_WAIT); const wait = DEBOUNCE_WAIT + 10;
return setTimeout(cb, wait);
}; };
beforeEach(function() { beforeEach(function() {
......
const frameUtil = require('../frame-util'); import * as frameUtil from '../frame-util';
describe('annotator.util.frame-util', function() { describe('annotator.util.frame-util', function() {
describe('findFrames', function() { describe('findFrames', function() {
......
const observable = require('../observable'); import * as observable from '../observable';
describe('observable', function() { describe('observable', function() {
describe('delay()', function() { describe('delay()', function() {
......
const { normalizeURI } = require('../url'); import { normalizeURI } from '../url';
describe('annotator.util.url', () => { describe('annotator.util.url', () => {
describe('normalizeURI', () => { describe('normalizeURI', () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment