diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-10-15 09:02:09 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-10-15 09:04:00 +0900 |
commit | 4c9d0433a6ac851e72d50d6fb0451baa9d35fd35 (patch) | |
tree | 5b831137fe327e94fd73339e2b395bfe3e98961c /src/content/components | |
parent | 042aa94936c9114f0a0fd05fb0a91df8f5565ecd (diff) |
make top-content component and frame-content component
Diffstat (limited to 'src/content/components')
-rw-r--r-- | src/content/components/common/follow.js (renamed from src/content/components/follow.js) | 0 | ||||
-rw-r--r-- | src/content/components/common/hint.css (renamed from src/content/components/hint.css) | 0 | ||||
-rw-r--r-- | src/content/components/common/hint.js (renamed from src/content/components/hint.js) | 0 | ||||
-rw-r--r-- | src/content/components/common/index.js | 46 | ||||
-rw-r--r-- | src/content/components/common/input.js (renamed from src/content/components/content-input.js) | 2 | ||||
-rw-r--r-- | src/content/components/common/keymapper.js (renamed from src/content/components/keymapper.js) | 0 | ||||
-rw-r--r-- | src/content/components/frame-content.js | 16 | ||||
-rw-r--r-- | src/content/components/top-content.js | 28 |
8 files changed, 91 insertions, 1 deletions
diff --git a/src/content/components/follow.js b/src/content/components/common/follow.js index 3f28cc2..3f28cc2 100644 --- a/src/content/components/follow.js +++ b/src/content/components/common/follow.js diff --git a/src/content/components/hint.css b/src/content/components/common/hint.css index 119dd21..119dd21 100644 --- a/src/content/components/hint.css +++ b/src/content/components/common/hint.css diff --git a/src/content/components/hint.js b/src/content/components/common/hint.js index cc46fd6..cc46fd6 100644 --- a/src/content/components/hint.js +++ b/src/content/components/common/hint.js diff --git a/src/content/components/common/index.js b/src/content/components/common/index.js new file mode 100644 index 0000000..7673134 --- /dev/null +++ b/src/content/components/common/index.js @@ -0,0 +1,46 @@ +import InputComponent from './input'; +import KeymapperComponent from './keymapper'; +import FollowComponent from './follow'; +import * as inputActions from 'content/actions/input'; +import messages from 'shared/messages'; + +export default class Common { + constructor(win, store) { + const follow = new FollowComponent(win, store); + const input = new InputComponent(win.document.body, store); + const keymapper = new KeymapperComponent(store); + + input.onKey((key, ctrl) => { + follow.key(key, ctrl); + keymapper.key(key, ctrl); + }); + + this.store = store; + this.children = [ + follow, + input, + keymapper, + ]; + + this.reloadSettings(); + } + + update() { + this.children.forEach(c => c.update()); + } + + onMessage(message) { + switch (message) { + case messages.SETTINGS_CHANGED: + this.reloadSettings(); + } + } + + reloadSettings() { + browser.runtime.sendMessage({ + type: messages.SETTINGS_QUERY, + }).then((settings) => { + this.store.dispatch(inputActions.setKeymaps(settings.keymaps)); + }); + } +} diff --git a/src/content/components/content-input.js b/src/content/components/common/input.js index 3e70bbb..df09894 100644 --- a/src/content/components/content-input.js +++ b/src/content/components/common/input.js @@ -1,4 +1,4 @@ -export default class ContentInputComponent { +export default class InputComponent { constructor(target) { this.pressed = {}; this.onKeyListeners = []; diff --git a/src/content/components/keymapper.js b/src/content/components/common/keymapper.js index 655c3f2..655c3f2 100644 --- a/src/content/components/keymapper.js +++ b/src/content/components/common/keymapper.js diff --git a/src/content/components/frame-content.js b/src/content/components/frame-content.js new file mode 100644 index 0000000..d2fb245 --- /dev/null +++ b/src/content/components/frame-content.js @@ -0,0 +1,16 @@ +import CommonComponent from './common'; + +export default class FrameContent { + + constructor(win, store) { + this.children = [new CommonComponent(win, store)]; + } + + update() { + this.children.forEach(c => c.update()); + } + + onMessage(message) { + this.children.forEach(c => c.onMessage(message)); + } +} diff --git a/src/content/components/top-content.js b/src/content/components/top-content.js new file mode 100644 index 0000000..9b58947 --- /dev/null +++ b/src/content/components/top-content.js @@ -0,0 +1,28 @@ +import CommonComponent from './common'; +import * as consoleFrames from '../console-frames'; +import messages from 'shared/messages'; + +export default class TopContent { + + constructor(win, store) { + this.win = win; + this.children = [new CommonComponent(win, store)]; + + // TODO make component + consoleFrames.initialize(window.document); + } + + update() { + this.children.forEach(c => c.update()); + } + + onMessage(message) { + switch (message.type) { + case messages.CONSOLE_HIDE_COMMAND: + this.win.focus(); + consoleFrames.blur(window.document); + return Promise.resolve(); + } + this.children.forEach(c => c.onMessage(message)); + } +} |