Commit 0636a9e0 authored by Robert Knight's avatar Robert Knight

Convert remaining CommonJS modules to ES modules

These modules have default exports and are imported by CoffeeScript
modules. Since we use CoffeeScript 1.x which doesn't support
`import`/`export` syntax, we use destructuring to access the default
export.
parent 9bb96cb1
const events = require('../shared/bridge-events'); import events from '../shared/bridge-events';
const ANNOTATION_COUNT_ATTR = 'data-hypothesis-annotation-count'; const ANNOTATION_COUNT_ATTR = 'data-hypothesis-annotation-count';
...@@ -10,7 +10,7 @@ const ANNOTATION_COUNT_ATTR = 'data-hypothesis-annotation-count'; ...@@ -10,7 +10,7 @@ const ANNOTATION_COUNT_ATTR = 'data-hypothesis-annotation-count';
* display annotation count. * display annotation count.
*/ */
function annotationCounts(rootEl, crossframe) { export default function annotationCounts(rootEl, crossframe) {
crossframe.on( crossframe.on(
events.PUBLIC_ANNOTATION_COUNT_CHANGED, events.PUBLIC_ANNOTATION_COUNT_CHANGED,
updateAnnotationCountElems updateAnnotationCountElems
...@@ -23,5 +23,3 @@ function annotationCounts(rootEl, crossframe) { ...@@ -23,5 +23,3 @@ function annotationCounts(rootEl, crossframe) {
}); });
} }
} }
module.exports = annotationCounts;
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// //
// It also listens for events from Guest when new annotations are created or // It also listens for events from Guest when new annotations are created or
// annotations successfully anchor and relays these to the sidebar app. // annotations successfully anchor and relays these to the sidebar app.
function AnnotationSync(bridge, options) { export default function AnnotationSync(bridge, options) {
const self = this; const self = this;
this.bridge = bridge; this.bridge = bridge;
...@@ -174,5 +174,3 @@ AnnotationSync.prototype._format = function(ann) { ...@@ -174,5 +174,3 @@ AnnotationSync.prototype._format = function(ann) {
msg: ann, msg: ann,
}; };
}; };
module.exports = AnnotationSync;
const events = require('../shared/bridge-events'); import events from '../shared/bridge-events';
const warnOnce = require('../shared/warn-once'); import warnOnce from '../shared/warn-once';
let _features = {}; let _features = {};
...@@ -7,7 +7,7 @@ const _set = features => { ...@@ -7,7 +7,7 @@ const _set = features => {
_features = features || {}; _features = features || {};
}; };
module.exports = { export default {
init: function(crossframe) { init: function(crossframe) {
crossframe.on(events.FEATURE_FLAGS_UPDATED, _set); crossframe.on(events.FEATURE_FLAGS_UPDATED, _set);
}, },
......
let FrameUtil = require('./util/frame-util'); import debounce from 'lodash.debounce';
let debounce = require('lodash.debounce');
import * as FrameUtil from './util/frame-util';
// Find difference of two arrays // Find difference of two arrays
let difference = (arrayA, arrayB) => { let difference = (arrayA, arrayB) => {
...@@ -8,7 +9,7 @@ let difference = (arrayA, arrayB) => { ...@@ -8,7 +9,7 @@ let difference = (arrayA, arrayB) => {
const DEBOUNCE_WAIT = 40; const DEBOUNCE_WAIT = 40;
class FrameObserver { export default class FrameObserver {
constructor(target) { constructor(target) {
this._target = target; this._target = target;
this._handledFrames = []; this._handledFrames = [];
...@@ -70,6 +71,5 @@ class FrameObserver { ...@@ -70,6 +71,5 @@ class FrameObserver {
} }
} }
} }
FrameObserver.DEBOUNCE_WAIT = DEBOUNCE_WAIT;
module.exports = FrameObserver; FrameObserver.DEBOUNCE_WAIT = DEBOUNCE_WAIT;
...@@ -10,7 +10,7 @@ adder = require('./adder') ...@@ -10,7 +10,7 @@ adder = require('./adder')
htmlAnchoring = require('./anchoring/html') htmlAnchoring = require('./anchoring/html')
highlighter = require('./highlighter') highlighter = require('./highlighter')
rangeUtil = require('./range-util') rangeUtil = require('./range-util')
selections = require('./selections') { default: selections } = require('./selections')
xpathRange = require('./anchoring/range') xpathRange = require('./anchoring/range')
{ normalizeURI } = require('./util/url') { normalizeURI } = require('./util/url')
......
...@@ -12,4 +12,4 @@ const RenderingStates = { ...@@ -12,4 +12,4 @@ const RenderingStates = {
FINISHED: 3, FINISHED: 3,
}; };
module.exports = RenderingStates; export default RenderingStates;
Plugin = require('../plugin') Plugin = require('../plugin')
AnnotationSync = require('../annotation-sync') { default: AnnotationSync } = require('../annotation-sync')
Bridge = require('../../shared/bridge') { default: Bridge } = require('../../shared/bridge')
Discovery = require('../../shared/discovery') { default: Discovery } = require('../../shared/discovery')
FrameUtil = require('../util/frame-util') FrameUtil = require('../util/frame-util')
FrameObserver = require('../frame-observer') { default: FrameObserver } = require('../frame-observer')
# Extracts individual keys from an object and returns a new one. # Extracts individual keys from an object and returns a new one.
extract = extract = (obj, keys...) -> extract = extract = (obj, keys...) ->
......
Plugin = require('../plugin') Plugin = require('../plugin')
RenderingStates = require('../pdfjs-rendering-states') { default: RenderingStates } = require('../pdfjs-rendering-states')
module.exports = class PDF extends Plugin module.exports = class PDF extends Plugin
documentLoaded: null documentLoaded: null
......
const observable = require('./util/observable'); import * as observable from './util/observable';
/** Returns the selected `DOMRange` in `document`. */ /** Returns the selected `DOMRange` in `document`. */
function selectedRange(document) { function selectedRange(document) {
...@@ -21,7 +21,7 @@ function selectedRange(document) { ...@@ -21,7 +21,7 @@ function selectedRange(document) {
* *
* @return Observable<DOMRange|null> * @return Observable<DOMRange|null>
*/ */
function selections(document) { export default function selections(document) {
// Get a stream of selection changes that occur whilst the user is not // Get a stream of selection changes that occur whilst the user is not
// making a selection with the mouse. // making a selection with the mouse.
let isMouseDown; let isMouseDown;
...@@ -54,5 +54,3 @@ function selections(document) { ...@@ -54,5 +54,3 @@ function selections(document) {
return selectedRange(document); return selectedRange(document);
}); });
} }
module.exports = selections;
...@@ -8,7 +8,7 @@ const SIDEBAR_TRIGGER_BTN_ATTR = 'data-hypothesis-trigger'; ...@@ -8,7 +8,7 @@ const SIDEBAR_TRIGGER_BTN_ATTR = 'data-hypothesis-trigger';
* @param {Object} showFn - Function which shows the sidebar. * @param {Object} showFn - Function which shows the sidebar.
*/ */
function trigger(rootEl, showFn) { export default function trigger(rootEl, showFn) {
const triggerElems = rootEl.querySelectorAll( const triggerElems = rootEl.querySelectorAll(
'[' + SIDEBAR_TRIGGER_BTN_ATTR + ']' '[' + SIDEBAR_TRIGGER_BTN_ATTR + ']'
); );
...@@ -22,5 +22,3 @@ function trigger(rootEl, showFn) { ...@@ -22,5 +22,3 @@ function trigger(rootEl, showFn) {
event.stopPropagation(); event.stopPropagation();
} }
} }
module.exports = trigger;
...@@ -3,10 +3,10 @@ raf = require('raf') ...@@ -3,10 +3,10 @@ raf = require('raf')
Hammer = require('hammerjs') Hammer = require('hammerjs')
Host = require('./host') Host = require('./host')
annotationCounts = require('./annotation-counts') { default: annotationCounts } = require('./annotation-counts')
sidebarTrigger = require('./sidebar-trigger') { default: sidebarTrigger } = require('./sidebar-trigger')
events = require('../shared/bridge-events') { default: events } = require('../shared/bridge-events')
features = require('./features') { default: features } = require('./features')
# Minimum width to which the frame can be resized. # Minimum width to which the frame can be resized.
MIN_RESIZE = 280 MIN_RESIZE = 280
......
events = require('../../shared/bridge-events') { default: events } = require('../../shared/bridge-events')
Sidebar = require('../sidebar') Sidebar = require('../sidebar')
{ $imports } = require('../sidebar') { $imports } = require('../sidebar')
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* This module defines the set of global events that are dispatched * This module defines the set of global events that are dispatched
* across the bridge between the sidebar and annotator * across the bridge between the sidebar and annotator
*/ */
module.exports = { export default {
// Events that the sidebar sends to the annotator // Events that the sidebar sends to the annotator
// ---------------------------------------------- // ----------------------------------------------
......
const extend = require('extend'); import extend from 'extend';
const RPC = require('./frame-rpc'); import RPC from './frame-rpc';
/** /**
* The Bridge service sets up a channel between frames and provides an events * The Bridge service sets up a channel between frames and provides an events
* API on top of it. * API on top of it.
*/ */
class Bridge { export default class Bridge {
constructor() { constructor() {
this.links = []; this.links = [];
this.channelListeners = {}; this.channelListeners = {};
...@@ -167,5 +167,3 @@ class Bridge { ...@@ -167,5 +167,3 @@ class Bridge {
return this; return this;
} }
} }
module.exports = Bridge;
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
* 5. Clients listen for "ack" messages. When they receive one from a server * 5. Clients listen for "ack" messages. When they receive one from a server
* they call the callback to `startDiscovery`. * they call the callback to `startDiscovery`.
*/ */
class Discovery { export default class Discovery {
/** /**
* @param {Window} target * @param {Window} target
* @param {Object} options * @param {Object} options
...@@ -227,5 +227,3 @@ class Discovery { ...@@ -227,5 +227,3 @@ class Discovery {
.replace(/\D/g, ''); .replace(/\D/g, '');
} }
} }
module.exports = Discovery;
...@@ -29,9 +29,7 @@ ...@@ -29,9 +29,7 @@
const VERSION = '1.0.0'; const VERSION = '1.0.0';
module.exports = RPC; export default function RPC(src, dst, origin, methods) {
function RPC(src, dst, origin, methods) {
if (!(this instanceof RPC)) return new RPC(src, dst, origin, methods); if (!(this instanceof RPC)) return new RPC(src, dst, origin, methods);
const self = this; const self = this;
this.src = src; this.src = src;
......
...@@ -11,7 +11,7 @@ let shownWarnings = {}; ...@@ -11,7 +11,7 @@ let shownWarnings = {};
* are concatenated into a string key which is used to determine if the warning * are concatenated into a string key which is used to determine if the warning
* has been logged before. * has been logged before.
*/ */
function warnOnce(...args) { export default function warnOnce(...args) {
const key = args.join(); const key = args.join();
if (key in shownWarnings) { if (key in shownWarnings) {
return; return;
...@@ -23,5 +23,3 @@ function warnOnce(...args) { ...@@ -23,5 +23,3 @@ function warnOnce(...args) {
warnOnce.reset = () => { warnOnce.reset = () => {
shownWarnings = {}; shownWarnings = {};
}; };
module.exports = warnOnce;
import fakeReduxStore from '../../test/fake-redux-store'; import fakeReduxStore from '../../test/fake-redux-store';
import persistedDefaults from '../persisted-defaults'; import persistedDefaults from '../persisted-defaults';
const DEFAULT_KEYS = { const DEFAULT_KEYS = {
......
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