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