aboutsummaryrefslogtreecommitdiff
path: root/src/content/components
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2019-05-19 09:34:40 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2019-05-19 09:34:40 +0900
commit4be04628e19392d8da9688d538cc3374e91005d8 (patch)
tree5c2299f6b85bf96dc9df65ddd7c27aef01b0ed69 /src/content/components
parente0c4182f14f908d13c8c814c7bc2b48a1791f881 (diff)
Remove unused components
Diffstat (limited to 'src/content/components')
-rw-r--r--src/content/components/common/follow.ts104
-rw-r--r--src/content/components/common/index.ts59
-rw-r--r--src/content/components/common/mark.ts44
-rw-r--r--src/content/components/frame-content.ts3
-rw-r--r--src/content/components/top-content/follow-controller.ts181
-rw-r--r--src/content/components/top-content/index.ts47
6 files changed, 0 insertions, 438 deletions
diff --git a/src/content/components/common/follow.ts b/src/content/components/common/follow.ts
deleted file mode 100644
index 413244e..0000000
--- a/src/content/components/common/follow.ts
+++ /dev/null
@@ -1,104 +0,0 @@
-import MessageListener from '../../MessageListener';
-import { LinkHint, InputHint } from '../../presenters/Hint';
-import * as messages from '../../../shared/messages';
-import Key from '../../domains/Key';
-import TabsClient, { TabsClientImpl } from '../../client/TabsClient';
-import FollowMasterClient, { FollowMasterClientImpl }
- from '../../client/FollowMasterClient';
-import FollowPresenter, { FollowPresenterImpl }
- from '../../presenters/FollowPresenter';
-
-let tabsClient: TabsClient = new TabsClientImpl();
-let followMasterClient: FollowMasterClient =
- new FollowMasterClientImpl(window.top);
-let followPresenter: FollowPresenter =
- new FollowPresenterImpl();
-
-interface Size {
- width: number;
- height: number;
-}
-
-interface Point {
- x: number;
- y: number;
-}
-
-export default class Follow {
- private enabled: boolean;
-
- constructor() {
- this.enabled = false;
-
- new MessageListener().onWebMessage(this.onMessage.bind(this));
- }
-
- key(key: Key): boolean {
- if (!this.enabled) {
- return false;
- }
- followMasterClient.sendKey(key);
- return true;
- }
-
- countHints(viewSize: Size, framePosition: Point) {
- let count = followPresenter.getTargetCount(viewSize, framePosition);
- followMasterClient.responseHintCount(count);
- }
-
- createHints(viewSize: Size, framePosition: Point, tags: string[]) {
- this.enabled = true;
- followPresenter.createHints(viewSize, framePosition, tags);
- }
-
- showHints(prefix: string) {
- followPresenter.filterHints(prefix);
- }
-
- removeHints() {
- followPresenter.clearHints();
- this.enabled = false;
- }
-
- async activateHints(
- tag: string, newTab: boolean, background: boolean,
- ): Promise<void> {
- let hint = followPresenter.getHint(tag);
- if (!hint) {
- return;
- }
-
- if (hint instanceof LinkHint) {
- let url = hint.getLink();
- // ignore taget='_blank'
- if (!newTab && hint.getLinkTarget() !== '_blank') {
- hint.click();
- return;
- }
- // eslint-disable-next-line no-script-url
- if (!url || url === '#' || url.toLowerCase().startsWith('javascript:')) {
- return;
- }
- await tabsClient.openUrl(url, newTab, background);
- } else if (hint instanceof InputHint) {
- hint.activate();
- }
- }
-
- onMessage(message: messages.Message, _sender: Window) {
- switch (message.type) {
- case messages.FOLLOW_REQUEST_COUNT_TARGETS:
- return this.countHints(message.viewSize, message.framePosition);
- case messages.FOLLOW_CREATE_HINTS:
- return this.createHints(
- message.viewSize, message.framePosition, message.tags);
- case messages.FOLLOW_SHOW_HINTS:
- return this.showHints(message.prefix);
- case messages.FOLLOW_ACTIVATE:
- return this.activateHints(
- message.tag, message.newTab, message.background);
- case messages.FOLLOW_REMOVE_HINTS:
- return this.removeHints();
- }
- }
-}
diff --git a/src/content/components/common/index.ts b/src/content/components/common/index.ts
deleted file mode 100644
index 1aacf51..0000000
--- a/src/content/components/common/index.ts
+++ /dev/null
@@ -1,59 +0,0 @@
-import InputDriver from './../../InputDriver';
-import FollowComponent from './follow';
-import MarkComponent from './mark';
-// import KeymapperComponent from './keymapper';
-import * as messages from '../../../shared/messages';
-import MessageListener from '../../MessageListener';
-import * as blacklists from '../../../shared/blacklists';
-import Key from '../../domains/Key';
-
-import AddonEnabledUseCase from '../../usecases/AddonEnabledUseCase';
-import SettingUseCase from '../../usecases/SettingUseCase';
-
-let addonEnabledUseCase = new AddonEnabledUseCase();
-let settingUseCase = new SettingUseCase();
-
-export default class Common {
- constructor(win: Window, store: any) {
- const input = new InputDriver(win.document.body);
- const follow = new FollowComponent();
- const mark = new MarkComponent(store);
- // const keymapper = new KeymapperComponent(store);
-
- input.onKey((key: Key) => follow.key(key));
- input.onKey((key: Key) => mark.key(key));
- // input.onKey((key: Key) => keymapper.key(key));
-
- this.reloadSettings();
-
- new MessageListener().onBackgroundMessage(this.onMessage.bind(this));
- }
-
- onMessage(message: messages.Message) {
- switch (message.type) {
- case messages.SETTINGS_CHANGED:
- return this.reloadSettings();
- case messages.ADDON_TOGGLE_ENABLED:
- return addonEnabledUseCase.toggle();
- }
- return undefined;
- }
-
- async reloadSettings() {
- try {
- let current = await settingUseCase.reload();
- let disabled = blacklists.includes(
- current.blacklist, window.location.href,
- );
- if (disabled) {
- addonEnabledUseCase.disable();
- } else {
- addonEnabledUseCase.enable();
- }
- } catch (e) {
- // Sometime sendMessage fails when background script is not ready.
- console.warn(e);
- setTimeout(() => this.reloadSettings(), 500);
- }
- }
-}
diff --git a/src/content/components/common/mark.ts b/src/content/components/common/mark.ts
deleted file mode 100644
index 058b873..0000000
--- a/src/content/components/common/mark.ts
+++ /dev/null
@@ -1,44 +0,0 @@
-import * as markActions from '../../actions/mark';
-import * as consoleFrames from '../..//console-frames';
-import Key from '../../domains/Key';
-
-import MarkUseCase from '../../usecases/MarkUseCase';
-
-let markUseCase = new MarkUseCase();
-
-const cancelKey = (key: Key): boolean => {
- return key.key === 'Esc' || key.key === '[' && Boolean(key.ctrlKey);
-};
-
-export default class MarkComponent {
- private store: any;
-
- constructor(store: any) {
- this.store = store;
- }
-
- // eslint-disable-next-line max-statements
- key(key: Key) {
- let { mark: markState } = this.store.getState();
-
- if (!markState.setMode && !markState.jumpMode) {
- return false;
- }
-
- if (cancelKey(key)) {
- this.store.dispatch(markActions.cancel());
- return true;
- }
-
- if (key.ctrlKey || key.metaKey || key.altKey) {
- consoleFrames.postError('Unknown mark');
- } else if (markState.setMode) {
- markUseCase.set(key.key);
- } else if (markState.jumpMode) {
- markUseCase.jump(key.key);
- }
-
- this.store.dispatch(markActions.cancel());
- return true;
- }
-}
diff --git a/src/content/components/frame-content.ts b/src/content/components/frame-content.ts
deleted file mode 100644
index ca999ba..0000000
--- a/src/content/components/frame-content.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-import CommonComponent from './common';
-
-export default CommonComponent;
diff --git a/src/content/components/top-content/follow-controller.ts b/src/content/components/top-content/follow-controller.ts
deleted file mode 100644
index 43c917e..0000000
--- a/src/content/components/top-content/follow-controller.ts
+++ /dev/null
@@ -1,181 +0,0 @@
-import * as followControllerActions from '../../actions/follow-controller';
-import * as messages from '../../../shared/messages';
-import MessageListener from '../../MessageListener';
-import HintKeyProducer from '../../hint-key-producer';
-
-import { SettingRepositoryImpl } from '../../repositories/SettingRepository';
-import FollowSlaveClient, { FollowSlaveClientImpl }
- from '../../client/FollowSlaveClient';
-
-let settingRepository = new SettingRepositoryImpl();
-
-export default class FollowController {
- private win: Window;
-
- private store: any;
-
- private state: {
- enabled?: boolean;
- newTab?: boolean;
- background?: boolean;
- keys?: string,
- };
-
- private keys: string[];
-
- private producer: HintKeyProducer | null;
-
- constructor(win: Window, store: any) {
- this.win = win;
- this.store = store;
- this.state = {};
- this.keys = [];
- this.producer = null;
-
- new MessageListener().onWebMessage(this.onMessage.bind(this));
-
- store.subscribe(() => {
- this.update();
- });
- }
-
- onMessage(message: messages.Message, sender: Window) {
- switch (message.type) {
- case messages.FOLLOW_START:
- return this.store.dispatch(
- followControllerActions.enable(message.newTab, message.background));
- case messages.FOLLOW_RESPONSE_COUNT_TARGETS:
- return this.create(message.count, sender);
- case messages.FOLLOW_KEY_PRESS:
- return this.keyPress(message.key, message.ctrlKey);
- }
- }
-
- update(): void {
- let prevState = this.state;
- this.state = this.store.getState().followController;
-
- if (!prevState.enabled && this.state.enabled) {
- this.count();
- } else if (prevState.enabled && !this.state.enabled) {
- this.remove();
- } else if (prevState.keys !== this.state.keys) {
- this.updateHints();
- }
- }
-
- updateHints(): void {
- let shown = this.keys.filter((key) => {
- return key.startsWith(this.state.keys as string);
- });
- if (shown.length === 1) {
- this.activate();
- this.store.dispatch(followControllerActions.disable());
- }
-
- this.broadcastMessage((c: FollowSlaveClient) => {
- c.filterHints(this.state.keys!!);
- });
- }
-
- activate(): void {
- this.broadcastMessage((c: FollowSlaveClient) => {
- c.activateIfExists(
- this.state.keys!!,
- this.state.newTab!!,
- this.state.background!!);
- });
- }
-
- keyPress(key: string, ctrlKey: boolean): boolean {
- if (key === '[' && ctrlKey) {
- this.store.dispatch(followControllerActions.disable());
- return true;
- }
- switch (key) {
- case 'Enter':
- this.activate();
- this.store.dispatch(followControllerActions.disable());
- break;
- case 'Esc':
- this.store.dispatch(followControllerActions.disable());
- break;
- case 'Backspace':
- case 'Delete':
- this.store.dispatch(followControllerActions.backspace());
- break;
- default:
- if (this.hintchars().includes(key)) {
- this.store.dispatch(followControllerActions.keyPress(key));
- }
- break;
- }
- return true;
- }
-
- count() {
- this.producer = new HintKeyProducer(this.hintchars());
- let doc = this.win.document;
- let viewWidth = this.win.innerWidth || doc.documentElement.clientWidth;
- let viewHeight = this.win.innerHeight || doc.documentElement.clientHeight;
- let frameElements = this.win.document.querySelectorAll('iframe');
-
- new FollowSlaveClientImpl(this.win).requestHintCount(
- { width: viewWidth, height: viewHeight },
- { x: 0, y: 0 });
-
- for (let ele of Array.from(frameElements)) {
- let { left: frameX, top: frameY } = ele.getBoundingClientRect();
- new FollowSlaveClientImpl(ele.contentWindow!!).requestHintCount(
- { width: viewWidth, height: viewHeight },
- { x: frameX, y: frameY },
- );
- }
- }
-
- create(count: number, sender: Window) {
- let produced = [];
- for (let i = 0; i < count; ++i) {
- produced.push((this.producer as HintKeyProducer).produce());
- }
- this.keys = this.keys.concat(produced);
-
- let doc = this.win.document;
- let viewWidth = this.win.innerWidth || doc.documentElement.clientWidth;
- let viewHeight = this.win.innerHeight || doc.documentElement.clientHeight;
- let pos = { x: 0, y: 0 };
- if (sender !== window) {
- let frameElements = this.win.document.querySelectorAll('iframe');
- let ele = Array.from(frameElements).find(e => e.contentWindow === sender);
- if (!ele) {
- // elements of the sender is gone
- return;
- }
- let { left: frameX, top: frameY } = ele.getBoundingClientRect();
- pos = { x: frameX, y: frameY };
- }
- new FollowSlaveClientImpl(sender).createHints(
- { width: viewWidth, height: viewHeight },
- pos,
- produced,
- );
- }
-
- remove() {
- this.keys = [];
- this.broadcastMessage((c: FollowSlaveClient) => {
- c.clearHints();
- });
- }
-
- private hintchars() {
- return settingRepository.get().properties.hintchars;
- }
-
- private broadcastMessage(f: (clinet: FollowSlaveClient) => void) {
- let windows = [window.self].concat(Array.from(window.frames as any));
- windows
- .map(w => new FollowSlaveClientImpl(w))
- .forEach(c => f(c));
- }
-}
diff --git a/src/content/components/top-content/index.ts b/src/content/components/top-content/index.ts
deleted file mode 100644
index 0f07653..0000000
--- a/src/content/components/top-content/index.ts
+++ /dev/null
@@ -1,47 +0,0 @@
-import CommonComponent from '../common';
-import FollowController from './follow-controller';
-import * as consoleFrames from '../../console-frames';
-import * as messages from '../../../shared/messages';
-import MessageListener from '../../MessageListener';
-import AddonEnabledUseCase from '../../usecases/AddonEnabledUseCase';
-import { ScrollPresenterImpl } from '../../presenters/ScrollPresenter';
-
-let addonEnabledUseCase = new AddonEnabledUseCase();
-let scrollPresenter = new ScrollPresenterImpl();
-
-export default class TopContent {
- private win: Window;
-
- constructor(win: Window, store: any) {
- this.win = win;
-
- new CommonComponent(win, store); // eslint-disable-line no-new
- new FollowController(win, store); // eslint-disable-line no-new
-
- // TODO make component
- consoleFrames.initialize(this.win.document);
-
- new MessageListener().onWebMessage(this.onWebMessage.bind(this));
- new MessageListener().onBackgroundMessage(
- this.onBackgroundMessage.bind(this));
- }
-
- onWebMessage(message: messages.Message) {
- switch (message.type) {
- case messages.CONSOLE_UNFOCUS:
- this.win.focus();
- consoleFrames.blur(window.document);
- }
- }
-
- onBackgroundMessage(message: messages.Message) {
- let addonEnabled = addonEnabledUseCase.getEnabled();
-
- switch (message.type) {
- case messages.ADDON_ENABLED_QUERY:
- return Promise.resolve(addonEnabled);
- case messages.TAB_SCROLL_TO:
- return scrollPresenter.scrollTo(message.x, message.y, false);
- }
- }
-}