diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2020-05-02 17:25:56 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-02 17:25:56 +0900 |
commit | 5df0537bcf65a341e79852b1b30379c73318529c (patch) | |
tree | aee5efe52412855f620cb514a13a2c14373f27b7 /src/content/usecases/FollowMasterUseCase.ts | |
parent | 685f2b7b69218b06b5bb676069e35f79c5048c9b (diff) | |
parent | 75abd90ecb8201ad845b266f96220d8adfe19b2d (diff) |
Merge pull request #749 from ueokande/qa-0.28
QA 0.28
Diffstat (limited to 'src/content/usecases/FollowMasterUseCase.ts')
-rw-r--r-- | src/content/usecases/FollowMasterUseCase.ts | 78 |
1 files changed, 40 insertions, 38 deletions
diff --git a/src/content/usecases/FollowMasterUseCase.ts b/src/content/usecases/FollowMasterUseCase.ts index 0e7f394..329f05a 100644 --- a/src/content/usecases/FollowMasterUseCase.ts +++ b/src/content/usecases/FollowMasterUseCase.ts @@ -1,10 +1,10 @@ -import { injectable, inject } from 'tsyringe'; -import FollowKeyRepository from '../repositories/FollowKeyRepository'; -import FollowMasterRepository from '../repositories/FollowMasterRepository'; -import FollowSlaveClient from '../client/FollowSlaveClient'; -import FollowSlaveClientFactory from '../client/FollowSlaveClientFactory'; -import SettingRepository from '../repositories/SettingRepository'; -import HintKeyProducer from './HintKeyProducer'; +import { injectable, inject } from "tsyringe"; +import FollowKeyRepository from "../repositories/FollowKeyRepository"; +import FollowMasterRepository from "../repositories/FollowMasterRepository"; +import FollowSlaveClient from "../client/FollowSlaveClient"; +import FollowSlaveClientFactory from "../client/FollowSlaveClientFactory"; +import SettingRepository from "../repositories/SettingRepository"; +import HintKeyProducer from "./HintKeyProducer"; @injectable() export default class FollowMasterUseCase { @@ -12,17 +12,17 @@ export default class FollowMasterUseCase { private producer: HintKeyProducer | null; constructor( - @inject('FollowKeyRepository') + @inject("FollowKeyRepository") private followKeyRepository: FollowKeyRepository, - @inject('FollowMasterRepository') + @inject("FollowMasterRepository") private followMasterRepository: FollowMasterRepository, - @inject('SettingRepository') + @inject("SettingRepository") private settingRepository: SettingRepository, - @inject('FollowSlaveClientFactory') - private followSlaveClientFactory: FollowSlaveClientFactory, + @inject("FollowSlaveClientFactory") + private followSlaveClientFactory: FollowSlaveClientFactory ) { this.producer = null; } @@ -36,19 +36,21 @@ export default class FollowMasterUseCase { const viewWidth = window.top.innerWidth; const viewHeight = window.top.innerHeight; - this.followSlaveClientFactory.create(window.top).requestHintCount( - { width: viewWidth, height: viewHeight }, - { x: 0, y: 0 }, - ); + this.followSlaveClientFactory + .create(window.top) + .requestHintCount( + { width: viewWidth, height: viewHeight }, + { x: 0, y: 0 } + ); - const frameElements = window.document.querySelectorAll('iframe'); + const frameElements = window.document.querySelectorAll("iframe"); for (let i = 0; i < frameElements.length; ++i) { const ele = frameElements[i] as HTMLFrameElement | HTMLIFrameElement; const { left: frameX, top: frameY } = ele.getBoundingClientRect(); const client = this.followSlaveClientFactory.create(ele.contentWindow!!); client.requestHintCount( { width: viewWidth, height: viewHeight }, - { x: frameX, y: frameY }, + { x: frameX, y: frameY } ); } } @@ -67,8 +69,10 @@ export default class FollowMasterUseCase { const viewHeight = window.innerHeight || doc.documentElement.clientHeight; let pos = { x: 0, y: 0 }; if (sender !== window) { - const frameElements = window.document.querySelectorAll('iframe'); - const ele = Array.from(frameElements).find(e => e.contentWindow === sender); + const frameElements = window.document.querySelectorAll("iframe"); + const ele = Array.from(frameElements).find( + (e) => e.contentWindow === sender + ); if (!ele) { // elements of the sender is gone return; @@ -77,11 +81,7 @@ export default class FollowMasterUseCase { pos = { x: frameX, y: frameY }; } const client = this.followSlaveClientFactory.create(sender); - client.createHints( - { width: viewWidth, height: viewHeight }, - pos, - produced, - ); + client.createHints({ width: viewWidth, height: viewHeight }, pos, produced); } cancelFollow(): void { @@ -110,17 +110,17 @@ export default class FollowMasterUseCase { enqueue(key: string): void { switch (key) { - case 'Enter': - this.activate(this.getCurrentTag()); - return; - case 'Esc': - this.cancelFollow(); - return; - case 'Backspace': - case 'Delete': - this.followKeyRepository.popKey(); - this.filter(this.getCurrentTag()); - return; + case "Enter": + this.activate(this.getCurrentTag()); + return; + case "Esc": + this.cancelFollow(); + return; + case "Backspace": + case "Delete": + this.followKeyRepository.popKey(); + this.filter(this.getCurrentTag()); + return; } this.followKeyRepository.pushKey(key); @@ -138,13 +138,15 @@ export default class FollowMasterUseCase { private broadcastToSlaves(handler: (client: FollowSlaveClient) => void) { const allFrames = [window.self].concat(Array.from(window.frames as any)); - const clients = allFrames.map(w => this.followSlaveClientFactory.create(w)); + const clients = allFrames.map((w) => + this.followSlaveClientFactory.create(w) + ); for (const client of clients) { handler(client); } } private getCurrentTag(): string { - return this.followKeyRepository.getKeys().join(''); + return this.followKeyRepository.getKeys().join(""); } } |