diff options
Diffstat (limited to 'src/content/actions')
-rw-r--r-- | src/content/actions/addon.ts | 10 | ||||
-rw-r--r-- | src/content/actions/find.ts | 40 | ||||
-rw-r--r-- | src/content/actions/follow-controller.ts | 12 | ||||
-rw-r--r-- | src/content/actions/index.ts | 151 | ||||
-rw-r--r-- | src/content/actions/input.ts | 6 | ||||
-rw-r--r-- | src/content/actions/mark.ts | 20 | ||||
-rw-r--r-- | src/content/actions/operation.ts | 25 | ||||
-rw-r--r-- | src/content/actions/setting.ts | 14 |
8 files changed, 196 insertions, 82 deletions
diff --git a/src/content/actions/addon.ts b/src/content/actions/addon.ts index b30cf16..8dedae0 100644 --- a/src/content/actions/addon.ts +++ b/src/content/actions/addon.ts @@ -1,11 +1,11 @@ -import messages from 'shared/messages'; -import actions from 'content/actions'; +import * as messages from '../../shared/messages'; +import * as actions from './index'; -const enable = () => setEnabled(true); +const enable = (): Promise<actions.AddonAction> => setEnabled(true); -const disable = () => setEnabled(false); +const disable = (): Promise<actions.AddonAction> => setEnabled(false); -const setEnabled = async(enabled) => { +const setEnabled = async(enabled: boolean): Promise<actions.AddonAction> => { await browser.runtime.sendMessage({ type: messages.ADDON_ENABLED_RESPONSE, enabled, diff --git a/src/content/actions/find.ts b/src/content/actions/find.ts index e08d7e5..6dd2ae6 100644 --- a/src/content/actions/find.ts +++ b/src/content/actions/find.ts @@ -5,28 +5,41 @@ // NOTE: window.find is not standard API // https://developer.mozilla.org/en-US/docs/Web/API/Window/find -import messages from 'shared/messages'; -import actions from 'content/actions'; +import * as messages from '../../shared/messages'; +import * as actions from './index'; import * as consoleFrames from '../console-frames'; -const find = (string, backwards) => { +const find = (str: string, backwards: boolean): boolean => { let caseSensitive = false; let wrapScan = true; // NOTE: aWholeWord dows not implemented, and aSearchInFrames does not work // because of same origin policy - let found = window.find(string, caseSensitive, backwards, wrapScan); + + // eslint-disable-next-line no-extra-parens + let found = (<any>window).find(str, caseSensitive, backwards, wrapScan); if (found) { return found; } - window.getSelection().removeAllRanges(); - return window.find(string, caseSensitive, backwards, wrapScan); + let sel = window.getSelection(); + if (sel) { + sel.removeAllRanges(); + } + + // eslint-disable-next-line no-extra-parens + return (<any>window).find(str, caseSensitive, backwards, wrapScan); }; -const findNext = async(currentKeyword, reset, backwards) => { +// eslint-disable-next-line max-statements +const findNext = async( + currentKeyword: string, reset: boolean, backwards: boolean, +): Promise<actions.FindAction> => { if (reset) { - window.getSelection().removeAllRanges(); + let sel = window.getSelection(); + if (sel) { + sel.removeAllRanges(); + } } let keyword = currentKeyword; @@ -41,7 +54,8 @@ const findNext = async(currentKeyword, reset, backwards) => { }); } if (!keyword) { - return consoleFrames.postError('No previous search keywords'); + await consoleFrames.postError('No previous search keywords'); + return { type: actions.NOOP }; } let found = find(keyword, backwards); if (found) { @@ -57,11 +71,15 @@ const findNext = async(currentKeyword, reset, backwards) => { }; }; -const next = (currentKeyword, reset) => { +const next = ( + currentKeyword: string, reset: boolean, +): Promise<actions.FindAction> => { return findNext(currentKeyword, reset, false); }; -const prev = (currentKeyword, reset) => { +const prev = ( + currentKeyword: string, reset: boolean, +): Promise<actions.FindAction> => { return findNext(currentKeyword, reset, true); }; diff --git a/src/content/actions/follow-controller.ts b/src/content/actions/follow-controller.ts index 006b248..115b3b6 100644 --- a/src/content/actions/follow-controller.ts +++ b/src/content/actions/follow-controller.ts @@ -1,6 +1,8 @@ -import actions from 'content/actions'; +import * as actions from './index'; -const enable = (newTab, background) => { +const enable = ( + newTab: boolean, background: boolean, +): actions.FollowAction => { return { type: actions.FOLLOW_CONTROLLER_ENABLE, newTab, @@ -8,20 +10,20 @@ const enable = (newTab, background) => { }; }; -const disable = () => { +const disable = (): actions.FollowAction => { return { type: actions.FOLLOW_CONTROLLER_DISABLE, }; }; -const keyPress = (key) => { +const keyPress = (key: string): actions.FollowAction => { return { type: actions.FOLLOW_CONTROLLER_KEY_PRESS, key: key }; }; -const backspace = () => { +const backspace = (): actions.FollowAction => { return { type: actions.FOLLOW_CONTROLLER_BACKSPACE, }; diff --git a/src/content/actions/index.ts b/src/content/actions/index.ts index 0a16fdf..18d0a69 100644 --- a/src/content/actions/index.ts +++ b/src/content/actions/index.ts @@ -1,31 +1,120 @@ -export default { - // Enable/disable - ADDON_SET_ENABLED: 'addon.set.enabled', - - // Settings - SETTING_SET: 'setting.set', - - // User input - INPUT_KEY_PRESS: 'input.key.press', - INPUT_CLEAR_KEYS: 'input.clear.keys', - - // Completion - COMPLETION_SET_ITEMS: 'completion.set.items', - COMPLETION_SELECT_NEXT: 'completions.select.next', - COMPLETION_SELECT_PREV: 'completions.select.prev', - - // Follow - FOLLOW_CONTROLLER_ENABLE: 'follow.controller.enable', - FOLLOW_CONTROLLER_DISABLE: 'follow.controller.disable', - FOLLOW_CONTROLLER_KEY_PRESS: 'follow.controller.key.press', - FOLLOW_CONTROLLER_BACKSPACE: 'follow.controller.backspace', - - // Find - FIND_SET_KEYWORD: 'find.set.keyword', - - // Mark - MARK_START_SET: 'mark.start.set', - MARK_START_JUMP: 'mark.start.jump', - MARK_CANCEL: 'mark.cancel', - MARK_SET_LOCAL: 'mark.set.local', -}; +import Redux from 'redux'; + +// Enable/disable +export const ADDON_SET_ENABLED = 'addon.set.enabled'; + +// Find +export const FIND_SET_KEYWORD = 'find.set.keyword'; + +// Settings +export const SETTING_SET = 'setting.set'; + +// User input +export const INPUT_KEY_PRESS = 'input.key.press'; +export const INPUT_CLEAR_KEYS = 'input.clear.keys'; + +// Completion +export const COMPLETION_SET_ITEMS = 'completion.set.items'; +export const COMPLETION_SELECT_NEXT = 'completions.select.next'; +export const COMPLETION_SELECT_PREV = 'completions.select.prev'; + +// Follow +export const FOLLOW_CONTROLLER_ENABLE = 'follow.controller.enable'; +export const FOLLOW_CONTROLLER_DISABLE = 'follow.controller.disable'; +export const FOLLOW_CONTROLLER_KEY_PRESS = 'follow.controller.key.press'; +export const FOLLOW_CONTROLLER_BACKSPACE = 'follow.controller.backspace'; + +// Mark +export const MARK_START_SET = 'mark.start.set'; +export const MARK_START_JUMP = 'mark.start.jump'; +export const MARK_CANCEL = 'mark.cancel'; +export const MARK_SET_LOCAL = 'mark.set.local'; + +export const NOOP = 'noop'; + +export interface AddonSetEnabledAction extends Redux.Action { + type: typeof ADDON_SET_ENABLED; + enabled: boolean; +} + +export interface FindSetKeywordAction extends Redux.Action { + type: typeof FIND_SET_KEYWORD; + keyword: string; + found: boolean; +} + +export interface SettingSetAction extends Redux.Action { + type: typeof SETTING_SET; + value: any; +} + +export interface InputKeyPressAction extends Redux.Action { + type: typeof INPUT_KEY_PRESS; + key: string; +} + +export interface InputClearKeysAction extends Redux.Action { + type: typeof INPUT_CLEAR_KEYS; +} + +export interface FollowControllerEnableAction extends Redux.Action { + type: typeof FOLLOW_CONTROLLER_ENABLE; + newTab: boolean; + background: boolean; +} + +export interface FollowControllerDisableAction extends Redux.Action { + type: typeof FOLLOW_CONTROLLER_DISABLE; +} + +export interface FollowControllerKeyPressAction extends Redux.Action { + type: typeof FOLLOW_CONTROLLER_KEY_PRESS; + key: string; +} + +export interface FollowControllerBackspaceAction extends Redux.Action { + type: typeof FOLLOW_CONTROLLER_BACKSPACE; +} + +export interface MarkStartSetAction extends Redux.Action { + type: typeof MARK_START_SET; +} + +export interface MarkStartJumpAction extends Redux.Action { + type: typeof MARK_START_JUMP; +} + +export interface MarkCancelAction extends Redux.Action { + type: typeof MARK_CANCEL; +} + +export interface MarkSetLocalAction extends Redux.Action { + type: typeof MARK_SET_LOCAL; + key: string; + x: number; + y: number; +} + +export interface NoopAction extends Redux.Action { + type: typeof NOOP; +} + +export type AddonAction = AddonSetEnabledAction; +export type FindAction = FindSetKeywordAction | NoopAction; +export type SettingAction = SettingSetAction; +export type InputAction = InputKeyPressAction | InputClearKeysAction; +export type FollowAction = + FollowControllerEnableAction | FollowControllerDisableAction | + FollowControllerKeyPressAction | FollowControllerBackspaceAction; +export type MarkAction = + MarkStartSetAction | MarkStartJumpAction | + MarkCancelAction | MarkSetLocalAction | NoopAction; + +export type Action = + AddonAction | + FindAction | + SettingAction | + InputAction | + FollowAction | + MarkAction | + NoopAction; diff --git a/src/content/actions/input.ts b/src/content/actions/input.ts index 465a486..21c912e 100644 --- a/src/content/actions/input.ts +++ b/src/content/actions/input.ts @@ -1,13 +1,13 @@ -import actions from 'content/actions'; +import * as actions from './index'; -const keyPress = (key) => { +const keyPress = (key: string): actions.InputAction => { return { type: actions.INPUT_KEY_PRESS, key, }; }; -const clearKeys = () => { +const clearKeys = (): actions.InputAction => { return { type: actions.INPUT_CLEAR_KEYS }; diff --git a/src/content/actions/mark.ts b/src/content/actions/mark.ts index 712a811..5eb9554 100644 --- a/src/content/actions/mark.ts +++ b/src/content/actions/mark.ts @@ -1,19 +1,19 @@ -import actions from 'content/actions'; -import messages from 'shared/messages'; +import * as actions from './index'; +import * as messages from '../../shared/messages'; -const startSet = () => { +const startSet = (): actions.MarkAction => { return { type: actions.MARK_START_SET }; }; -const startJump = () => { +const startJump = (): actions.MarkAction => { return { type: actions.MARK_START_JUMP }; }; -const cancel = () => { +const cancel = (): actions.MarkAction => { return { type: actions.MARK_CANCEL }; }; -const setLocal = (key, x, y) => { +const setLocal = (key: string, x: number, y: number): actions.MarkAction => { return { type: actions.MARK_SET_LOCAL, key, @@ -22,22 +22,22 @@ const setLocal = (key, x, y) => { }; }; -const setGlobal = (key, x, y) => { +const setGlobal = (key: string, x: number, y: number): actions.MarkAction => { browser.runtime.sendMessage({ type: messages.MARK_SET_GLOBAL, key, x, y, }); - return { type: '' }; + return { type: actions.NOOP }; }; -const jumpGlobal = (key) => { +const jumpGlobal = (key: string): actions.MarkAction => { browser.runtime.sendMessage({ type: messages.MARK_JUMP_GLOBAL, key, }); - return { type: '' }; + return { type: actions.NOOP }; }; export { diff --git a/src/content/actions/operation.ts b/src/content/actions/operation.ts index ed9b2cf..6acb407 100644 --- a/src/content/actions/operation.ts +++ b/src/content/actions/operation.ts @@ -1,16 +1,21 @@ -import operations from 'shared/operations'; -import messages from 'shared/messages'; -import * as scrolls from 'content/scrolls'; -import * as navigates from 'content/navigates'; -import * as focuses from 'content/focuses'; -import * as urls from 'content/urls'; -import * as consoleFrames from 'content/console-frames'; +import * as operations from '../../shared/operations'; +import * as actions from './index'; +import * as messages from '../../shared/messages'; +import * as scrolls from '../scrolls'; +import * as navigates from '../navigates'; +import * as focuses from '../focuses'; +import * as urls from '../urls'; +import * as consoleFrames from '../console-frames'; import * as addonActions from './addon'; import * as markActions from './mark'; -import * as properties from 'shared/settings/properties'; +import * as properties from '../../shared/settings/properties'; // eslint-disable-next-line complexity, max-lines-per-function -const exec = (operation, settings, addonEnabled) => { +const exec = ( + operation: operations.Operation, + settings: any, + addonEnabled: boolean, +): Promise<actions.Action> | actions.Action => { let smoothscroll = settings.properties.smoothscroll || properties.defaults.smoothscroll; switch (operation.type) { @@ -98,7 +103,7 @@ const exec = (operation, settings, addonEnabled) => { operation, }); } - return { type: '' }; + return { type: actions.NOOP }; }; export { exec }; diff --git a/src/content/actions/setting.ts b/src/content/actions/setting.ts index 1c15dd7..a8f049a 100644 --- a/src/content/actions/setting.ts +++ b/src/content/actions/setting.ts @@ -1,15 +1,15 @@ -import actions from 'content/actions'; -import * as keyUtils from 'shared/utils/keys'; -import operations from 'shared/operations'; -import messages from 'shared/messages'; +import * as actions from './index'; +import * as keyUtils from '../../shared/utils/keys'; +import * as operations from '../../shared/operations'; +import * as messages from '../../shared/messages'; const reservedKeymaps = { '<Esc>': { type: operations.CANCEL }, '<C-[>': { type: operations.CANCEL }, }; -const set = (value) => { - let entries = []; +const set = (value: any): actions.SettingAction => { + let entries: any[] = []; if (value.keymaps) { let keymaps = { ...value.keymaps, ...reservedKeymaps }; entries = Object.entries(keymaps).map((entry) => { @@ -27,7 +27,7 @@ const set = (value) => { }; }; -const load = async() => { +const load = async(): Promise<actions.SettingAction> => { let settings = await browser.runtime.sendMessage({ type: messages.SETTINGS_QUERY, }); |