Commit c3e2a91b authored by Eduardo Sanz García's avatar Eduardo Sanz García Committed by Eduardo

Convert the rest of the default export into named exports

parent b1209d74
import { startApp } from '@hypothesis/frontend-shared/lib/pattern-library';
import ButtonPatterns from './components/ButtonPatterns';
import sidebarIcons from '../../src/sidebar/icons';
import { sidebarIcons } from '../../src/sidebar/icons';
/** @type {import('@hypothesis/frontend-shared/lib/pattern-library').PlaygroundRoute[]} */
const extraRoutes = [
......
/* global PDFViewerApplication */
import warnOnce from '../../shared/warn-once';
import { warnOnce } from '../../shared/warn-once';
import { matchQuote } from './match-quote';
import { createPlaceholder } from './placeholder';
import { TextPosition, TextRange } from './text-range';
......
......@@ -251,7 +251,7 @@ class FakePDFViewer {
*
* The original is defined at https://github.com/mozilla/pdf.js/blob/master/web/app.js
*/
export default class FakePDFViewerApplication {
export class FakePDFViewerApplication {
/**
* @param {Options} options
*/
......
......@@ -27,7 +27,7 @@ import minimalJSON from './minimal.json';
import wikipediaDoc from './wikipedia-regression-testing.html';
import wikipediaJSON from './wikipedia-regression-testing.json';
export default [
export const htmlBaselines = [
{
name: 'Minimal Document',
html: minimalDoc,
......
import * as html from '../html';
import fixture from './html-anchoring-fixture.html';
import htmlBaselines from './html-baselines';
import { htmlBaselines } from './html-baselines';
/** Return all text node children of `container`. */
function textNodes(container) {
......
......@@ -3,7 +3,7 @@ import * as pdfAnchoring from '../pdf';
import { matchQuote } from '../match-quote';
import { TextRange } from '../text-range';
import FakePDFViewerApplication from './fake-pdf-viewer-application';
import { FakePDFViewerApplication } from './fake-pdf-viewer-application';
/**
* Return a DOM Range which refers to the specified `text` in `container`.
......
......@@ -22,7 +22,7 @@
* @return {object} - Any config settings returned by hypothesisConfig()
*
*/
export default function configFuncSettingsFrom(window_) {
export function configFuncSettingsFrom(window_) {
if (!window_.hasOwnProperty('hypothesisConfig')) {
return {};
}
......
import { isBrowserExtension } from './is-browser-extension';
import settingsFrom from './settings';
import { settingsFrom } from './settings';
import { toBoolean } from '../../shared/type-coercions';
import { urlFromLinkTag } from './url-from-link-tag';
......
import { parseJsonConfig } from '../../boot/parse-json-config';
import { toBoolean } from '../../shared/type-coercions';
import configFuncSettingsFrom from './config-func-settings-from';
import { configFuncSettingsFrom } from './config-func-settings-from';
import { urlFromLinkTag } from './url-from-link-tag';
/**
......@@ -20,7 +20,7 @@ import { urlFromLinkTag } from './url-from-link-tag';
/**
* @return {SettingsGetters}
*/
export default function settingsFrom(window_) {
export function settingsFrom(window_) {
// Prioritize the `window.hypothesisConfig` function over the JSON format
// Via uses `window.hypothesisConfig` and makes it non-configurable and non-writable.
// In addition, Via sets the `ignoreOtherConfiguration` option to prevent configuration merging.
......
import configFuncSettingsFrom from '../config-func-settings-from';
import { configFuncSettingsFrom } from '../config-func-settings-from';
describe('annotator.config.configFuncSettingsFrom', () => {
const sandbox = sinon.createSandbox();
......
import { getConfig } from '../index';
import { $imports } from '../index';
import { getConfig, $imports } from '../index';
describe('annotator/config/index', () => {
let fakeSettingsFrom;
......@@ -20,7 +19,7 @@ describe('annotator/config/index', () => {
fakeIsBrowserExtension = sinon.stub();
$imports.$mock({
'./settings': fakeSettingsFrom,
'./settings': { settingsFrom: fakeSettingsFrom },
'./is-browser-extension': {
isBrowserExtension: fakeIsBrowserExtension,
},
......@@ -135,16 +134,18 @@ describe('annotator/config/index', () => {
beforeEach(() => {
// Remove all fake values
$imports.$mock({
'./settings': sinon.stub().returns({
hostPageSetting: sinon.stub().returns(undefined),
annotations: undefined,
clientUrl: undefined,
group: undefined,
notebookAppUrl: undefined,
showHighlights: undefined,
sidebarAppUrl: undefined,
query: undefined,
}),
'./settings': {
settingsFrom: sinon.stub().returns({
hostPageSetting: sinon.stub().returns(undefined),
annotations: undefined,
clientUrl: undefined,
group: undefined,
notebookAppUrl: undefined,
showHighlights: undefined,
sidebarAppUrl: undefined,
query: undefined,
}),
},
});
});
......
import settingsFrom from '../settings';
import { $imports } from '../settings';
import { settingsFrom, $imports } from '../settings';
describe('annotator/config/settingsFrom', () => {
let fakeConfigFuncSettingsFrom;
......@@ -12,7 +11,9 @@ describe('annotator/config/settingsFrom', () => {
fakeParseJsonConfig = sinon.stub().returns({});
$imports.$mock({
'./config-func-settings-from': fakeConfigFuncSettingsFrom,
'./config-func-settings-from': {
configFuncSettingsFrom: fakeConfigFuncSettingsFrom,
},
'./url-from-link-tag': {
urlFromLinkTag: fakeUrlFromLinkTag,
},
......
import warnOnce from '../shared/warn-once';
import { warnOnce } from '../shared/warn-once';
let _features = {};
......
......@@ -20,7 +20,7 @@ import pointerIcon from '../images/icons/pointer.svg';
* Set of icons used by the annotator part of the application via the `SvgIcon`
* component.
*/
export default {
export const annotatorIcons = {
annotate: annotateIcon,
cancel,
caution,
......
......@@ -6,8 +6,8 @@ import 'preact/debug';
// Load icons.
import { registerIcons } from '@hypothesis/frontend-shared';
import iconSet from './icons';
registerIcons(iconSet);
import { annotatorIcons } from './icons';
registerIcons(annotatorIcons);
import { PortProvider } from '../shared/messaging';
import { getConfig } from './config/index';
......
import { delay } from '../../../test-util/wait';
import FakePDFViewerApplication from '../../anchoring/test/fake-pdf-viewer-application';
import { FakePDFViewerApplication } from '../../anchoring/test/fake-pdf-viewer-application';
import { RenderingStates } from '../../anchoring/pdf';
import { createPlaceholder } from '../../anchoring/placeholder';
import { PDFIntegration, isPDF, $imports } from '../pdf';
......
......@@ -8,7 +8,7 @@ const SIDEBAR_TRIGGER_BTN_ATTR = 'data-hypothesis-trigger';
* @param {object} showFn - Function which shows the sidebar.
*/
export default function trigger(rootEl, showFn) {
export function sidebarTrigger(rootEl, showFn) {
const triggerElems = rootEl.querySelectorAll(
'[' + SIDEBAR_TRIGGER_BTN_ATTR + ']'
);
......
......@@ -9,7 +9,7 @@ import { annotationCounts } from './annotation-counts';
import { BucketBar } from './bucket-bar';
import { createAppConfig } from './config/app';
import { features } from './features';
import sidebarTrigger from './sidebar-trigger';
import { sidebarTrigger } from './sidebar-trigger';
import { ToolbarController } from './toolbar';
import { createShadowRoot } from './util/shadow-root';
......
......@@ -16,7 +16,7 @@ describe('features - annotation layer', () => {
beforeEach(() => {
fakeWarnOnce = sinon.stub();
$imports.$mock({
'../shared/warn-once': fakeWarnOnce,
'../shared/warn-once': { warnOnce: fakeWarnOnce },
});
features.init({
......
import sidebarTrigger from '../sidebar-trigger';
import { sidebarTrigger } from '../sidebar-trigger';
describe('sidebarTrigger', () => {
let triggerEl1;
......
......@@ -8,7 +8,7 @@
import { parseJsonConfig } from './parse-json-config';
import { bootHypothesisClient, bootSidebarApp } from './boot';
import processUrlTemplate from './url-template';
import { processUrlTemplate } from './url-template';
import { isBrowserSupported } from './browser-check';
// @ts-ignore - This file is generated before the boot bundle is built.
......
import processUrlTemplate from '../url-template';
import { processUrlTemplate } from '../url-template';
describe('processUrlTemplate', () => {
let fakeDocument;
......
......@@ -36,7 +36,7 @@ function currentScriptOrigin(document_ = document) {
* @param {string} url
* @param {Document} document_
*/
export default function processUrlTemplate(url, document_ = document) {
export function processUrlTemplate(url, document_ = document) {
if (url.indexOf('{') === -1) {
// Not a template. This should always be the case in production.
return url;
......
import warnOnce from '../warn-once';
import { warnOnce } from '../warn-once';
describe('warnOnce', () => {
beforeEach(() => {
......
......@@ -11,7 +11,7 @@ let shownWarnings = {};
* are concatenated into a string key which is used to determine if the warning
* has been logged before.
*/
export default function warnOnce(...args) {
export function warnOnce(...args) {
const key = args.join();
if (key in shownWarnings) {
return;
......
......@@ -2,7 +2,7 @@ import { LinkButton } from '@hypothesis/frontend-shared';
import classnames from 'classnames';
import { useCallback, useLayoutEffect, useRef, useState } from 'preact/hooks';
import observeElementSize from '../util/observe-element-size';
import { observeElementSize } from '../util/observe-element-size';
import { withServices } from '../service-context';
import { applyTheme } from '../helpers/theme';
......
......@@ -3,7 +3,7 @@ import { useMemo, useState } from 'preact/hooks';
import { serviceConfig } from '../../config/service-config';
import { isThirdPartyUser } from '../../helpers/account-id';
import { orgName } from '../../helpers/group-list-item-common';
import groupsByOrganization from '../../helpers/group-organizations';
import { groupsByOrganization } from '../../helpers/group-organizations';
import { isThirdPartyService } from '../../helpers/is-third-party-service';
import { withServices } from '../../service-context';
import { useStoreProxy } from '../../store/use-store';
......
......@@ -110,10 +110,12 @@ describe('GroupList', () => {
it('sorts groups within each section by organization', () => {
const testGroups = populateGroupSections();
const fakeGroupOrganizations = groups =>
const fakeGroupsByOrganization = groups =>
groups.sort((a, b) => a.id.localeCompare(b.id));
$imports.$mock({
'../../helpers/group-organizations': fakeGroupOrganizations,
'../../helpers/group-organizations': {
groupsByOrganization: fakeGroupsByOrganization,
},
});
const wrapper = createGroupList();
......@@ -123,7 +125,7 @@ describe('GroupList', () => {
sections.forEach(section => {
assert.deepEqual(
section.prop('groups'),
fakeGroupOrganizations(testGroups)
fakeGroupsByOrganization(testGroups)
);
});
});
......
......@@ -3,7 +3,7 @@ import { useCallback, useMemo, useState } from 'preact/hooks';
import { useStoreProxy } from '../store/use-store';
import { withServices } from '../service-context';
import VersionData from '../helpers/version-data';
import { VersionData } from '../helpers/version-data';
import SidebarPanel from './SidebarPanel';
import Tutorial from './Tutorial';
......
......@@ -2,7 +2,7 @@ import classnames from 'classnames';
import { useEffect, useMemo, useRef } from 'preact/hooks';
import { replaceLinksWithEmbeds } from '../media-embedder';
import renderMarkdown from '../render-markdown';
import { renderMathAndMarkdown as renderMarkdown } from '../render-markdown';
/**
* @typedef MarkdownViewProps
......
......@@ -5,7 +5,7 @@ import { withServices } from '../service-context';
/**
* @typedef VersionInfoProps
* @prop {import('../helpers/version-data').default} versionData - Object with version information
* @prop {import('../helpers/version-data').VersionData} versionData - Object with version information
* @prop {import('../services/toast-messenger').ToastMessengerService} toastMessenger
*/
......
import { mount } from 'enzyme';
import useRootThread from '../use-root-thread';
import { $imports } from '../use-root-thread';
import useRootThread, { $imports } from '../use-root-thread';
describe('sidebar/components/hooks/use-root-thread', () => {
let fakeStore;
......@@ -20,7 +19,9 @@ describe('sidebar/components/hooks/use-root-thread', () => {
$imports.$mock({
'../../store/use-store': { useStoreProxy: () => fakeStore },
'../../helpers/thread-annotations': fakeThreadAnnotations,
'../../helpers/thread-annotations': {
threadAnnotations: fakeThreadAnnotations,
},
});
// Mount a dummy component to be able to use the `useRootThread` hook
......
import { useMemo } from 'preact/hooks';
import { useStoreProxy } from '../../store/use-store';
import threadAnnotations from '../../helpers/thread-annotations';
import { threadAnnotations } from '../../helpers/thread-annotations';
/** @typedef {import('../../helpers/build-thread').Thread} Thread */
......
......@@ -39,7 +39,9 @@ describe('Excerpt', () => {
document.body.appendChild(container);
$imports.$mock({
'../util/observe-element-size': fakeObserveElementSize,
'../util/observe-element-size': {
observeElementSize: fakeObserveElementSize,
},
});
});
......
......@@ -41,7 +41,7 @@ describe('HelpPanel', () => {
$imports.$mock(mockImportedComponents());
$imports.$mock({
'../store/use-store': { useStoreProxy: () => fakeStore },
'../helpers/version-data': FakeVersionData,
'../helpers/version-data': { VersionData: FakeVersionData },
});
});
......
import { mount } from 'enzyme';
import MarkdownView from '../MarkdownView';
import { $imports } from '../MarkdownView';
import MarkdownView, { $imports } from '../MarkdownView';
import { checkAccessibility } from '../../../test-util/accessibility';
describe('MarkdownView', () => {
let fakeMediaEmbedder;
let fakeRenderMarkdown;
let fakeRenderMathAndMarkdown;
let fakeReplaceLinksWithEmbeds;
beforeEach(() => {
fakeRenderMarkdown = markdown => `rendered:${markdown}`;
fakeMediaEmbedder = {
replaceLinksWithEmbeds: sinon.stub(),
};
fakeRenderMathAndMarkdown = markdown => `rendered:${markdown}`;
fakeReplaceLinksWithEmbeds = sinon.stub();
$imports.$mock({
'../render-markdown': fakeRenderMarkdown,
'../media-embedder': fakeMediaEmbedder,
'../render-markdown': {
renderMathAndMarkdown: fakeRenderMathAndMarkdown,
},
'../media-embedder': {
replaceLinksWithEmbeds: fakeReplaceLinksWithEmbeds,
},
});
});
......@@ -46,7 +47,7 @@ describe('MarkdownView', () => {
it('replaces links with embeds in rendered output', () => {
const wrapper = mount(<MarkdownView markdown="**test**" />);
const rendered = wrapper.find('.MarkdownView').getDOMNode();
assert.calledWith(fakeMediaEmbedder.replaceLinksWithEmbeds, rendered, {
assert.calledWith(fakeReplaceLinksWithEmbeds, rendered, {
className: 'MarkdownView__embed',
});
});
......
import { mount } from 'enzyme';
import { act } from 'preact/test-utils';
import MenuItem from '../MenuItem';
import { $imports } from '../MenuItem';
import MenuItem, { $imports } from '../MenuItem';
import { checkAccessibility } from '../../../test-util/accessibility';
import { mockImportedComponents } from '../../../test-util/mock-imported-components';
......
import getApiUrl from './get-api-url';
import hostConfig from './host-config';
import { getApiUrl } from './get-api-url';
import { hostPageConfig as hostConfig } from './host-config';
import * as postMessageJsonRpc from '../util/postmessage-json-rpc';
/**
......
......@@ -8,7 +8,7 @@ import { serviceConfig } from './service-config';
* @throws {Error} If the settings has a service but the service doesn't have an apiUrl
*
*/
export default function getApiUrl(settings) {
export function getApiUrl(settings) {
const service = serviceConfig(settings);
if (service) {
......
......@@ -15,7 +15,7 @@ import {
* @param {Window} window
* @return {HostConfig}
*/
export default function hostPageConfig(window) {
export function hostPageConfig(window) {
const config = parseConfigFragment(window.location.href);
// Known configuration parameters which we will import from the host page.
......
import { fetchConfig, $imports } from '../fetch-config';
describe('sidebar/config/fetch-config', () => {
let fakeHostConfig;
let fakeHostPageConfig;
let fakeJsonRpc;
let fakeWindow;
let fakeApiUrl;
let fakeTopWindow;
beforeEach(() => {
fakeHostConfig = sinon.stub();
fakeHostPageConfig = sinon.stub();
fakeJsonRpc = {
call: sinon.stub(),
};
fakeApiUrl = sinon.stub().returns('https://dev.hypothes.is/api/');
$imports.$mock({
'./host-config': fakeHostConfig,
'./host-config': { hostPageConfig: fakeHostPageConfig },
'../util/postmessage-json-rpc': fakeJsonRpc,
'./get-api-url': fakeApiUrl,
'./get-api-url': { getApiUrl: fakeApiUrl },
});
// By default, embedder provides no custom config.
fakeHostConfig.returns({});
fakeHostPageConfig.returns({});
// By default, fetching config from parent frames fails.
fakeJsonRpc.call.throws(new Error('call() response not set'));
......@@ -59,7 +59,7 @@ describe('sidebar/config/fetch-config', () => {
it('merges the hostPageConfig onto appConfig and returns the result', async () => {
// hostPageConfig shall take precedent over appConfig
const appConfig = { foo: 'bar', appType: 'via' };
fakeHostConfig.returns({ foo: 'baz' });
fakeHostPageConfig.returns({ foo: 'baz' });
const mergedConfig = await fetchConfig(appConfig);
assert.deepEqual(mergedConfig, {
foo: 'baz',
......@@ -79,7 +79,7 @@ describe('sidebar/config/fetch-config', () => {
// exposed to the document itself.
const expectedTimeout = 3000;
beforeEach(() => {
fakeHostConfig.returns({
fakeHostPageConfig.returns({
requestConfigFromFrame: 'https://embedder.com',
});
sinon.stub(console, 'warn');
......@@ -169,7 +169,7 @@ describe('sidebar/config/fetch-config', () => {
// exposed to the document itself.
beforeEach(() => {
fakeJsonRpc.call.resolves({});
fakeHostConfig.returns({
fakeHostPageConfig.returns({
requestConfigFromFrame: {
origin: 'https://embedder.com',
ancestorLevel: 2,
......@@ -192,7 +192,7 @@ describe('sidebar/config/fetch-config', () => {
[0, 1, 2].forEach(level => {
it(`finds ${level}'th ancestor window according to how high the level is`, async () => {
fakeHostConfig.returns({
fakeHostPageConfig.returns({
requestConfigFromFrame: {
origin: 'https://embedder.com',
ancestorLevel: level,
......@@ -205,7 +205,7 @@ describe('sidebar/config/fetch-config', () => {
});
it('throws an error when target ancestor exceeds top window', async () => {
fakeHostConfig.returns({
fakeHostPageConfig.returns({
requestConfigFromFrame: {
origin: 'https://embedder.com',
ancestorLevel: 10, // The top window is only 2 levels high
......@@ -279,7 +279,7 @@ describe('sidebar/config/fetch-config', () => {
});
it('creates a merged config and also adds back the `group` value from the host config', async () => {
fakeHostConfig.returns({
fakeHostPageConfig.returns({
requestConfigFromFrame: {
origin: 'https://embedder.com',
ancestorLevel: 2,
......@@ -306,7 +306,7 @@ describe('sidebar/config/fetch-config', () => {
});
it('missing ancestorLevel', async () => {
fakeHostConfig.returns({
fakeHostPageConfig.returns({
requestConfigFromFrame: {
origin: 'https://embedder.com',
// missing ancestorLevel
......@@ -319,7 +319,7 @@ describe('sidebar/config/fetch-config', () => {
});
it('missing origin', async () => {
fakeHostConfig.returns({
fakeHostPageConfig.returns({
requestConfigFromFrame: {
// missing origin
ancestorLevel: 2,
......
import getApiUrl from '../get-api-url';
import { getApiUrl } from '../get-api-url';
describe('sidebar/config/get-api-url', () => {
context('when there is a service object in settings', () => {
......
import { addConfigFragment } from '../../../shared/config-fragment';
import hostPageConfig from '../host-config';
import { hostPageConfig } from '../host-config';
function fakeWindow(config) {
return {
......
import warnOnce from '../shared/warn-once';
import { warnOnce } from '../shared/warn-once';
import { normalizeGroupIds } from './helpers/groups';
......
......@@ -284,7 +284,7 @@ const replySortCompareFn = (a, b) => {
* @return {Thread} - The root thread, whose children are the top-level
* annotations to display.
*/
export default function buildThread(annotations, options) {
export function buildThread(annotations, options) {
const hasSelection = options.selected.length > 0;
const hasForcedVisible = options.forcedVisible.length > 0;
......
import immutable from '../util/immutable';
import { immutable } from '../util/immutable';
/**
* @typedef {import('../../types/api').Group} Group
......@@ -83,7 +83,7 @@ function organizations(groups) {
* @param {Array<Group>} groups
* @return {Array<object>} - groups sorted by which organization they're in
*/
export default function groupsByOrganization(groups) {
export function groupsByOrganization(groups) {
const orgs = organizations(groups);
const defaultOrganizationGroups = [];
const sortedGroups = [];
......
import buildThread from '../build-thread';
import { buildThread } from '../build-thread';
import * as metadata from '../../helpers/annotation-metadata';
// Fixture with two top level annotations, one note and one reply
......
import * as orgFixtures from '../../test/group-fixtures';
import groupsByOrganization from '../group-organizations';
import { groupsByOrganization } from '../group-organizations';
describe('sidebar/helpers/group-organizations', () => {
context('when sorting organizations and their contained groups', () => {
......
import * as annotationFixtures from '../../test/annotation-fixtures';
import threadAnnotations from '../thread-annotations';
import { threadAnnotations, $imports } from '../thread-annotations';
import { sorters } from '../thread-sorters';
import { $imports } from '../thread-annotations';
import immutable from '../../util/immutable';
import { immutable } from '../../util/immutable';
const fixtures = immutable({
emptyThread: {
......@@ -45,9 +44,9 @@ describe('sidebar/helpers/thread-annotations', () => {
};
$imports.$mock({
'./build-thread': fakeBuildThread,
'./build-thread': { buildThread: fakeBuildThread },
'../util/search-filter': fakeSearchFilter,
'./view-filter': fakeFilterAnnotations,
'./view-filter': { filterAnnotations: fakeFilterAnnotations },
});
});
......
import VersionData from '../version-data';
import { VersionData } from '../version-data';
describe('sidebar/helpers/version-data', () => {
let clock;
......
import filterAnnotations, { $imports } from '../view-filter';
import { filterAnnotations, $imports } from '../view-filter';
function isoDateWithAge(age) {
return new Date(Date.now() - age * 1000).toISOString();
......
import buildThread from './build-thread';
import { buildThread } from './build-thread';
import memoize from '../util/memoize';
import { memoize } from '../util/memoize';
import { generateFacetedFilter } from '../util/search-filter';
import filterAnnotations from './view-filter';
import { filterAnnotations } from './view-filter';
import { shouldShowInTab } from './tabs';
import { sorters } from './thread-sorters';
......@@ -71,6 +71,4 @@ function buildRootThread(threadState) {
return buildThread(threadState.annotations, options);
}
const threadAnnotations = memoize(buildRootThread);
export default threadAnnotations;
export const threadAnnotations = memoize(buildRootThread);
......@@ -19,7 +19,7 @@
* @prop {DocMetadata} [metadata] - Document metadata
*/
export default class VersionData {
export class VersionData {
/**
* @param {AuthState} userInfo
* @param {DocumentInfo[]} documentInfo - Metadata for connected frames.
......
......@@ -158,7 +158,7 @@ const fieldMatchers = {
* `generateFacetedFilter`.
* @return {string[]} IDs of matching annotations.
*/
export default function filterAnnotations(annotations, filters) {
export function filterAnnotations(annotations, filters) {
// Convert the input filter object into a filter tree, expanding "any"
// filters.
const fieldFilters = Object.entries(filters)
......
......@@ -56,7 +56,7 @@ import pointerIcon from '../images/icons/pointer.svg';
* Set of icons used by the sidebar application via the `SvgIcon`
* component.
*/
export default {
export const sidebarIcons = {
add: plus,
annotate: annotateIcon,
'arrow-left': arrowLeft,
......
......@@ -7,7 +7,7 @@ import {
startServer as startRPCServer,
preStartServer as preStartRPCServer,
} from './cross-origin-rpc.js';
import disableOpenerForExternalLinks from './util/disable-opener-for-external-links';
import { disableOpenerForExternalLinks } from './util/disable-opener-for-external-links';
import * as sentry from './util/sentry';
// Read settings rendered into sidebar app HTML by service/extension.
......@@ -100,9 +100,9 @@ function setupFrameSync(frameSync, store) {
// Register icons used by the sidebar app (and maybe other assets in future).
import { registerIcons } from '@hypothesis/frontend-shared';
import iconSet from './icons';
import { sidebarIcons } from './icons';
registerIcons(iconSet);
registerIcons(sidebarIcons);
// The entry point component for the app.
import { render } from 'preact';
......
......@@ -131,7 +131,7 @@ function insertMath(html, mathBlocks) {
}, html);
}
export default function renderMathAndMarkdown(markdown) {
export function renderMathAndMarkdown(markdown) {
// KaTeX takes care of escaping its input, so we want to avoid passing its
// output through the HTML sanitizer. Therefore we first extract the math
// blocks from the input, render and sanitize the remaining markdown and then
......
import { TinyEmitter } from 'tiny-emitter';
import { serviceConfig } from '../config/service-config';
import OAuthClient from '../util/oauth-client';
import { OAuthClient } from '../util/oauth-client';
import { resolve } from '../util/url';
/**
......
import { generateHexString } from '../../shared/random';
import warnOnce from '../../shared/warn-once';
import { Socket } from '../websocket';
import { warnOnce } from '../../shared/warn-once';
import { watch } from '../util/watch';
import { Socket } from '../websocket';
/**
* `StreamerService` manages the WebSocket connection to the Hypothesis Real-Time
......
import { Injector } from '../../../shared/injector';
import FakeWindow from '../../test/fake-window';
import { FakeWindow } from '../../test/fake-window';
import { AuthService, $imports } from '../auth';
const DEFAULT_TOKEN_EXPIRES_IN_SECS = 1000;
......@@ -87,7 +87,7 @@ describe('AuthService', () => {
fakeWindow = new FakeWindow();
$imports.$mock({
'../util/oauth-client': FakeOAuthClient,
'../util/oauth-client': { OAuthClient: FakeOAuthClient },
});
auth = new Injector()
......
import * as annotationFixtures from '../../test/annotation-fixtures';
import createFakeStore from '../../test/fake-redux-store';
import { fakeReduxStore } from '../../test/fake-redux-store';
import { waitFor } from '../../../test-util/wait';
import { AutosaveService, $imports } from '../autosave';
......@@ -14,7 +14,7 @@ describe('AutosaveService', () => {
fakeAnnotationsService = { save: sinon.stub().resolves() };
fakeNewHighlights = sinon.stub().returns([]);
fakeRetryPromiseOperation = sinon.stub().callsFake(callback => callback());
fakeStore = createFakeStore({}, { newHighlights: fakeNewHighlights });
fakeStore = fakeReduxStore({}, { newHighlights: fakeNewHighlights });
$imports.$mock({
'../util/retry': {
......
......@@ -2,7 +2,7 @@ import EventEmitter from 'tiny-emitter';
import { Injector } from '../../../shared/injector';
import * as annotationFixtures from '../../test/annotation-fixtures';
import createFakeStore from '../../test/fake-redux-store';
import { fakeReduxStore } from '../../test/fake-redux-store';
import { delay } from '../../../test-util/wait';
import { FrameSyncService, $imports, formatAnnot } from '../frame-sync';
......@@ -91,7 +91,7 @@ describe('FrameSyncService', () => {
discover: sinon.stub().resolves(sidebarPort),
};
fakeStore = createFakeStore(
fakeStore = fakeReduxStore(
{ annotations: [] },
{
allAnnotations() {
......
import { delay, waitFor } from '../../../test-util/wait';
import fakeReduxStore from '../../test/fake-redux-store';
import { fakeReduxStore } from '../../test/fake-redux-store';
import { GroupsService, $imports } from '../groups';
/**
......
import fakeReduxStore from '../../test/fake-redux-store';
import { fakeReduxStore } from '../../test/fake-redux-store';
import { PersistedDefaultsService } from '../persisted-defaults';
const DEFAULT_KEYS = {
......
import EventEmitter from 'tiny-emitter';
import { delay } from '../../../test-util/wait';
import fakeReduxStore from '../../test/fake-redux-store';
import { fakeReduxStore } from '../../test/fake-redux-store';
import { StreamerService, $imports } from '../streamer';
const fixtures = {
......@@ -129,7 +129,7 @@ describe('StreamerService', () => {
fakeWarnOnce = sinon.stub();
$imports.$mock({
'../../shared/warn-once': fakeWarnOnce,
'../../shared/warn-once': { warnOnce: fakeWarnOnce },
'../websocket': { Socket: FakeSocket },
});
});
......
......@@ -3,7 +3,7 @@
import * as redux from 'redux';
import thunk from 'redux-thunk';
import immutable from '../util/immutable';
import { immutable } from '../util/immutable';
import { createReducer, bindSelectors } from './util';
......
......@@ -10,7 +10,7 @@
*
* @param {import("redux").Store} store
*/
export default function debugMiddleware(store) {
export function debugMiddleware(store) {
/* eslint-disable no-console */
let serial = 0;
......
import { createStore } from './create-store';
import debugMiddleware from './debug-middleware';
import activity from './modules/activity';
import annotations from './modules/annotations';
import defaults from './modules/defaults';
import directLinked from './modules/direct-linked';
import drafts from './modules/drafts';
import filters from './modules/filters';
import frames from './modules/frames';
import groups from './modules/groups';
import links from './modules/links';
import realTimeUpdates from './modules/real-time-updates';
import route from './modules/route';
import selection from './modules/selection';
import session from './modules/session';
import sidebarPanels from './modules/sidebar-panels';
import toastMessages from './modules/toast-messages';
import viewer from './modules/viewer';
import { debugMiddleware } from './debug-middleware';
import { activity } from './modules/activity';
import { annotations } from './modules/annotations';
import { defaults } from './modules/defaults';
import { directLinked } from './modules/direct-linked';
import { drafts } from './modules/drafts';
import { filters } from './modules/filters';
import { framesModule as frames } from './modules/frames';
import { groups } from './modules/groups';
import { links } from './modules/links';
import { realTimeUpdates } from './modules/real-time-updates';
import { routeModule as route } from './modules/route';
import { selection } from './modules/selection';
import { session } from './modules/session';
import { sidebarPanels } from './modules/sidebar-panels';
import { toastMessages } from './modules/toast-messages';
import { viewer } from './modules/viewer';
/**
* @template M
......
......@@ -190,7 +190,7 @@ function isSavingAnnotation(state, annotation) {
/** @typedef {import('../../../types/api').Annotation} Annotation */
export default createStoreModule(initialState, {
export const activity = createStoreModule(initialState, {
reducers,
namespace: 'activity',
......
......@@ -19,7 +19,7 @@ import { countIf, toTrueMap, trueKeys } from '../../util/collections';
import * as util from '../util';
import { createStoreModule } from '../create-store';
import route from './route';
import { routeModule as route } from './route';
/**
* Return a copy of `current` with all matching annotations in `annotations`
......@@ -559,7 +559,7 @@ function savedAnnotations(state) {
});
}
export default createStoreModule(initialState, {
export const annotations = createStoreModule(initialState, {
namespace: 'annotations',
reducers,
actionCreators: {
......
......@@ -49,7 +49,7 @@ function getDefaults(state) {
return state;
}
export default createStoreModule(initialState, {
export const defaults = createStoreModule(initialState, {
namespace: 'defaults',
reducers,
actionCreators: {
......
......@@ -142,7 +142,7 @@ function directLinkedGroupFetchFailed(state) {
return state.directLinkedGroupFetchFailed;
}
export default createStoreModule(initialState, {
export const directLinked = createStoreModule(initialState, {
namespace: 'directLinked',
reducers,
actionCreators: {
......
......@@ -186,7 +186,7 @@ const unsavedAnnotations = createSelector(
drafts => drafts.filter(d => !d.annotation.id).map(d => d.annotation)
);
export default createStoreModule(initialState, {
export const drafts = createStoreModule(initialState, {
namespace: 'drafts',
reducers,
actionCreators: {
......
......@@ -279,7 +279,7 @@ function hasAppliedFilter(state) {
return !!(state.query || Object.keys(getFilters(state)).length);
}
export default createStoreModule(initialState, {
export const filters = createStoreModule(initialState, {
namespace: 'filters',
reducers,
actionCreators: {
......
......@@ -155,7 +155,7 @@ const searchUris = createShallowEqualSelector(
uris => uris
);
export default createStoreModule(initialState, {
export const framesModule = createStoreModule(initialState, {
namespace: 'frames',
reducers,
......
......@@ -3,7 +3,7 @@ import { createSelector } from 'reselect';
import * as util from '../util';
import { createStoreModule } from '../create-store';
import session from './session';
import { session } from './session';
/**
* @typedef {import('../../../types/api').Group} Group
......@@ -261,7 +261,7 @@ const getCurrentlyViewingGroups = createSelector(
}
);
export default createStoreModule(initialState, {
export const groups = createStoreModule(initialState, {
namespace: 'groups',
reducers,
actionCreators: {
......
......@@ -51,7 +51,7 @@ function getLink(state, linkName, params = {}) {
return url;
}
export default createStoreModule(initialState, {
export const links = createStoreModule(initialState, {
namespace: 'links',
reducers,
actionCreators: {
......
......@@ -12,9 +12,9 @@ import { createSelector } from 'reselect';
import { createStoreModule } from '../create-store';
import { actionTypes } from '../util';
import annotations from './annotations';
import groups from './groups';
import route from './route';
import { annotations } from './annotations';
import { groups } from './groups';
import { routeModule as route } from './route';
const initialState = {
/**
......@@ -193,7 +193,7 @@ function hasPendingDeletion(state, id) {
return state.pendingDeletions.hasOwnProperty(id);
}
export default createStoreModule(initialState, {
export const realTimeUpdates = createStoreModule(initialState, {
namespace: 'realTimeUpdates',
reducers,
actionCreators: {
......
......@@ -63,7 +63,7 @@ function routeParams(state) {
return state.params;
}
export default createStoreModule(initialState, {
export const routeModule = createStoreModule(initialState, {
namespace: 'route',
reducers,
actionCreators: {
......
......@@ -381,7 +381,7 @@ const sortKeys = createSelector(
}
);
export default createStoreModule(initialState, {
export const selection = createStoreModule(initialState, {
namespace: 'selection',
reducers,
......
......@@ -117,7 +117,7 @@ function profile(state) {
return state.profile;
}
export default createStoreModule(initialState, {
export const session = createStoreModule(initialState, {
namespace: 'session',
reducers,
......
......@@ -121,7 +121,7 @@ function isSidebarPanelOpen(state, panelName) {
return state.activePanelName === panelName;
}
export default createStoreModule(initialState, {
export const sidebarPanels = createStoreModule(initialState, {
namespace: 'sidebarPanels',
reducers,
......
import { createStore } from '../../create-store';
import activity from '../activity';
import { activity } from '../activity';
describe('sidebar/store/modules/activity', () => {
let store;
......
import * as fixtures from '../../../test/annotation-fixtures';
import * as metadata from '../../../helpers/annotation-metadata';
import { createStore } from '../../create-store';
import annotations from '../annotations';
import route from '../route';
import { annotations } from '../annotations';
import { routeModule as route } from '../route';
function createTestStore() {
return createStore([annotations, route], [{}]);
......
import { createStore } from '../../create-store';
import defaults from '../defaults';
import { defaults } from '../defaults';
describe('store/modules/defaults', () => {
let store;
......
import { createStore } from '../../create-store';
import directLinked from '../direct-linked';
import { directLinked } from '../direct-linked';
describe('sidebar/store/modules/direct-linked', () => {
let store;
......
import { createStore } from '../../create-store';
import annotations from '../annotations';
import drafts from '../drafts';
import { annotations } from '../annotations';
import { drafts } from '../drafts';
import { Draft } from '../drafts';
import selection from '../selection';
import immutable from '../../../util/immutable';
import { selection } from '../selection';
import { immutable } from '../../../util/immutable';
const fixtures = immutable({
draftWithText: {
......
import { createStore } from '../../create-store';
import filters from '../filters';
import selection from '../selection';
import { filters } from '../filters';
import { selection } from '../selection';
describe('sidebar/store/modules/filters', () => {
let store;
......
import { createStore } from '../../create-store';
import frames from '../frames';
import { framesModule as frames } from '../frames';
describe('sidebar/store/modules/frames', () => {
let store;
......
import { createStore } from '../../create-store';
import groups from '../groups';
import session from '../session';
import immutable from '../../../util/immutable';
import { groups } from '../groups';
import { session } from '../session';
import { immutable } from '../../../util/immutable';
describe('sidebar/store/modules/groups', () => {
const publicGroup = immutable({
......
import { createStore } from '../../create-store';
import links from '../links';
import { links } from '../links';
describe('sidebar/store/modules/links', () => {
let store;
......
import { createStore } from '../../create-store';
import annotations from '../annotations';
import groups from '../groups';
import realTimeUpdates from '../real-time-updates';
import { $imports } from '../real-time-updates';
import selection from '../selection';
import { annotations } from '../annotations';
import { groups } from '../groups';
import { realTimeUpdates, $imports } from '../real-time-updates';
import { selection } from '../selection';
const { removeAnnotations } = annotations.actionCreators;
const { focusGroup } = groups.actionCreators;
......@@ -38,17 +37,17 @@ describe('sidebar/store/modules/real-time-updates', () => {
$imports.$mock({
'./annotations': {
default: {
annotations: {
selectors: { annotationExists: fakeAnnotationExists },
},
},
'./groups': {
default: {
groups: {
selectors: { focusedGroupId: fakeFocusedGroupId },
},
},
'./route': {
default: {
routeModule: {
selectors: { route: fakeRoute },
},
},
......
import { createStore } from '../../create-store';
import route from '../route';
import { routeModule as route } from '../route';
describe('store/modules/route', () => {
let store;
......
import { createStore } from '../../create-store';
import annotations from '../annotations';
import filters from '../filters';
import selection from '../selection';
import route from '../route';
import { annotations } from '../annotations';
import { filters } from '../filters';
import { selection } from '../selection';
import { routeModule as route } from '../route';
import * as fixtures from '../../../test/annotation-fixtures';
describe('sidebar/store/modules/selection', () => {
......
import { createStore } from '../../create-store';
import session from '../session';
import { session } from '../session';
describe('sidebar/store/modules/session', () => {
let fakeSettings;
......
import { createStore } from '../../create-store';
import sidebarPanels from '../sidebar-panels';
import { sidebarPanels } from '../sidebar-panels';
describe('sidebar/store/modules/sidebar-panels', () => {
let store;
......
import { createStore } from '../../create-store';
import toastMessages from '../toast-messages';
import { toastMessages } from '../toast-messages';
describe('store/modules/toast-messages', () => {
let store;
......
import { createStore } from '../../create-store';
import viewer from '../viewer';
import { viewer } from '../viewer';
describe('store/modules/viewer', () => {
let store;
......
......@@ -112,7 +112,7 @@ function hasMessage(state, type, text) {
});
}
export default createStoreModule(initialState, {
export const toastMessages = createStoreModule(initialState, {
namespace: 'toastMessages',
reducers,
actionCreators: {
......
......@@ -43,7 +43,7 @@ function hasSidebarOpened(state) {
return state.sidebarHasOpened;
}
export default createStoreModule(initialState, {
export const viewer = createStoreModule(initialState, {
namespace: 'viewer',
reducers,
actionCreators: {
......
......@@ -2,7 +2,7 @@
import * as redux from 'redux';
import debugMiddleware from '../debug-middleware';
import { debugMiddleware } from '../debug-middleware';
function id(state) {
return state;
......
import * as annotationFixtures from '../../test/annotation-fixtures';
import { createSidebarStore } from '../index';
import immutable from '../../util/immutable';
import { immutable } from '../../util/immutable';
const defaultAnnotation = annotationFixtures.defaultAnnotation;
const newAnnotation = annotationFixtures.newAnnotation;
......
import fakeStore from '../../test/fake-redux-store';
import { fakeReduxStore } from '../../test/fake-redux-store';
import * as util from '../util';
......@@ -194,7 +194,7 @@ describe('sidebar/store/util', () => {
let store;
beforeEach(() => {
store = fakeStore({
store = fakeReduxStore({
fake: { val: 0 },
});
});
......
......@@ -16,8 +16,8 @@ configure({ adapter: new Adapter() });
// Make all the icons that are available for use with `SvgIcon` in the actual
// app available in the tests. This enables validation of icon names passed to
// `SvgIcon`.
import sidebarIcons from '../icons';
import annotatorIcons from '../../annotator/icons';
import { sidebarIcons } from '../icons';
import { annotatorIcons } from '../../annotator/icons';
import { registerIcons } from '@hypothesis/frontend-shared';
registerIcons({
...sidebarIcons,
......
......@@ -38,7 +38,7 @@ describe('sidebar/cross-origin-rpc', () => {
$imports.$mock({
'./helpers/groups': { normalizeGroupIds: fakeNormalizeGroupIds },
'../shared/warn-once': fakeWarnOnce,
'../shared/warn-once': { warnOnce: fakeWarnOnce },
});
});
......
......@@ -11,7 +11,7 @@ import * as redux from 'redux';
* returned store.
* @return {object} Redux store
*/
export default function fakeStore(initialState, methods) {
export function fakeReduxStore(initialState, methods) {
function update(state, action) {
if (action.state) {
return Object.assign({}, state, action.state);
......
export default class FakeWindow {
export class FakeWindow {
constructor() {
this.callbacks = [];
......
import renderMarkdown from '../render-markdown';
import { $imports } from '../render-markdown';
import { renderMathAndMarkdown, $imports } from '../render-markdown';
describe('render-markdown', () => {
let render;
......@@ -19,7 +18,7 @@ describe('render-markdown', () => {
},
});
render = markdown => renderMarkdown(markdown);
render = markdown => renderMathAndMarkdown(markdown);
});
afterEach(() => {
......@@ -61,21 +60,21 @@ describe('render-markdown', () => {
// library. This is not an extensive test of sanitization behavior, that
// is left to DOMPurify's tests.
assert.equal(
renderMarkdown('one **two** <script>alert("three")</script>'),
renderMathAndMarkdown('one **two** <script>alert("three")</script>'),
'<p>one <strong>two</strong> </p>'
);
});
it('should open links in a new window', () => {
assert.equal(
renderMarkdown('<a href="http://example.com">test</a>'),
renderMathAndMarkdown('<a href="http://example.com">test</a>'),
'<p><a href="http://example.com" target="_blank">test</a></p>'
);
});
it('should render strikethrough', () => {
assert.equal(
renderMarkdown('This is ~~no longer the case~~'),
renderMathAndMarkdown('This is ~~no longer the case~~'),
'<p>This is <del>no longer the case</del></p>'
);
});
......
......@@ -15,7 +15,7 @@
*
* @param {Element} root - Root element
*/
export default function disableOpenerForExternalLinks(root) {
export function disableOpenerForExternalLinks(root) {
root.addEventListener('click', event => {
const target = /** @type {HTMLElement} */ (event.target);
......
......@@ -28,7 +28,7 @@ function deepFreeze(object) {
* @param {object} object
* @return {object} Returns the input object
*/
export default function immutable(object) {
export function immutable(object) {
if (process.env.NODE_ENV === 'production') {
return object;
} else {
......
......@@ -10,7 +10,7 @@
* @param {(arg: Arg) => Result} fn
* @return {(arg: Arg) => Result}
*/
export default function memoize(fn) {
export function memoize(fn) {
if (fn.length !== 1) {
throw new Error('Memoize input must be a function of one argument');
}
......
......@@ -39,7 +39,7 @@ export class TokenError extends Error {
* OAuthClient handles interaction with the annotation service's OAuth
* endpoints.
*/
export default class OAuthClient {
export class OAuthClient {
/**
* Create a new OAuthClient
*
......
......@@ -13,7 +13,7 @@ import { ListenerCollection } from '../../shared/listener-collection';
* element when a change in its size is detected.
* @return {() => void}
*/
export default function observeElementSize(element, onSizeChanged) {
export function observeElementSize(element, onSizeChanged) {
if (typeof ResizeObserver !== 'undefined') {
const observer = new ResizeObserver(() =>
onSizeChanged(element.clientWidth, element.clientHeight)
......
......@@ -2,7 +2,7 @@ import * as Sentry from '@sentry/browser';
import { parseConfigFragment } from '../../shared/config-fragment';
import { handleErrorsInFrames } from '../../shared/frame-error-capture';
import warnOnce from '../../shared/warn-once';
import { warnOnce } from '../../shared/warn-once';
/**
* @typedef SentryConfig
......
import disableOpenerForExternalLinks from '../disable-opener-for-external-links';
import { disableOpenerForExternalLinks } from '../disable-opener-for-external-links';
describe('sidebar.util.disable-opener-for-external-links', () => {
let containerEl;
......
import immutable from '../immutable';
import { immutable } from '../immutable';
describe('immutable', () => {
it('deeply freezes objects', () => {
......
import memoize from '../memoize';
import { memoize } from '../memoize';
describe('memoize', () => {
let count = 0;
......
import fetchMock from 'fetch-mock';
import FakeWindow from '../../test/fake-window';
import OAuthClient, { TokenError, $imports } from '../oauth-client';
import { FakeWindow } from '../../test/fake-window';
import { OAuthClient, TokenError, $imports } from '../oauth-client';
const fixtures = {
tokenResponse: {
......
import observeElementSize from '../observe-element-size';
import { observeElementSize } from '../observe-element-size';
/**
* Wait for a condition to become true.
......
......@@ -27,7 +27,7 @@ describe('sidebar/util/sentry', () => {
'../../shared/frame-error-capture': {
handleErrorsInFrames: fakeHandleErrorsInFrames,
},
'../../shared/warn-once': fakeWarnOnce,
'../../shared/warn-once': { warnOnce: fakeWarnOnce },
});
});
......
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