Unverified Commit 73dd54e1 authored by Robert Knight's avatar Robert Knight Committed by GitHub

Merge pull request #1703 from hypothesis/convert-remaining-es-modules

Convert remaining CommonJS modules to ES modules
parents d3505e58 9e83ff3b
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) => {
return arrayA.filter(x => !arrayB.includes(x)); return arrayA.filter(x => !arrayB.includes(x));
}; };
const DEBOUNCE_WAIT = 40; export 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,3 @@ class FrameObserver { ...@@ -70,6 +71,3 @@ class FrameObserver {
} }
} }
} }
FrameObserver.DEBOUNCE_WAIT = DEBOUNCE_WAIT;
module.exports = FrameObserver;
...@@ -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 = {
......
...@@ -1453,9 +1453,9 @@ babel-plugin-istanbul@^6.0.0: ...@@ -1453,9 +1453,9 @@ babel-plugin-istanbul@^6.0.0:
test-exclude "^6.0.0" test-exclude "^6.0.0"
babel-plugin-mockable-imports@^1.5.1: babel-plugin-mockable-imports@^1.5.1:
version "1.5.2" version "1.6.0"
resolved "https://registry.yarnpkg.com/babel-plugin-mockable-imports/-/babel-plugin-mockable-imports-1.5.2.tgz#bd2095f0c10496ca74de236a7ee096b0062abb74" resolved "https://registry.yarnpkg.com/babel-plugin-mockable-imports/-/babel-plugin-mockable-imports-1.6.0.tgz#ae8c817327bc84a6258915456934d7d8d5a67999"
integrity sha512-R2UdySrsMaOr/6Jrj27V5Ryy6Gpt7d398fggqtZ3fd1/OF2rpJcb9ymjbGx2NLm4P9NQyvqAU570YtgWmA71RA== integrity sha512-+CpQXtdmLBT/AaU4lM2EFwE5DnYVtHprpmzSrQls0Zd0FaHcGKJPdN10PQMachMNVh38rADXTd5TwGNMvHW85g==
babel-plugin-transform-async-to-promises@^0.8.6: babel-plugin-transform-async-to-promises@^0.8.6:
version "0.8.15" version "0.8.15"
......
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