aboutsummaryrefslogtreecommitdiff
path: root/src/content/actions
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/actions')
-rw-r--r--src/content/actions/addon.js19
-rw-r--r--src/content/actions/addon.ts19
-rw-r--r--src/content/actions/find.js68
-rw-r--r--src/content/actions/find.ts100
-rw-r--r--src/content/actions/follow-controller.ts (renamed from src/content/actions/follow-controller.js)12
-rw-r--r--src/content/actions/index.js31
-rw-r--r--src/content/actions/index.ts122
-rw-r--r--src/content/actions/input.js16
-rw-r--r--src/content/actions/input.ts17
-rw-r--r--src/content/actions/mark.js46
-rw-r--r--src/content/actions/mark.ts46
-rw-r--r--src/content/actions/operation.ts (renamed from src/content/actions/operation.js)27
-rw-r--r--src/content/actions/setting.js37
-rw-r--r--src/content/actions/setting.ts28
14 files changed, 354 insertions, 234 deletions
diff --git a/src/content/actions/addon.js b/src/content/actions/addon.js
deleted file mode 100644
index b30cf16..0000000
--- a/src/content/actions/addon.js
+++ /dev/null
@@ -1,19 +0,0 @@
-import messages from 'shared/messages';
-import actions from 'content/actions';
-
-const enable = () => setEnabled(true);
-
-const disable = () => setEnabled(false);
-
-const setEnabled = async(enabled) => {
- await browser.runtime.sendMessage({
- type: messages.ADDON_ENABLED_RESPONSE,
- enabled,
- });
- return {
- type: actions.ADDON_SET_ENABLED,
- enabled,
- };
-};
-
-export { enable, disable, setEnabled };
diff --git a/src/content/actions/addon.ts b/src/content/actions/addon.ts
new file mode 100644
index 0000000..8dedae0
--- /dev/null
+++ b/src/content/actions/addon.ts
@@ -0,0 +1,19 @@
+import * as messages from '../../shared/messages';
+import * as actions from './index';
+
+const enable = (): Promise<actions.AddonAction> => setEnabled(true);
+
+const disable = (): Promise<actions.AddonAction> => setEnabled(false);
+
+const setEnabled = async(enabled: boolean): Promise<actions.AddonAction> => {
+ await browser.runtime.sendMessage({
+ type: messages.ADDON_ENABLED_RESPONSE,
+ enabled,
+ });
+ return {
+ type: actions.ADDON_SET_ENABLED,
+ enabled,
+ };
+};
+
+export { enable, disable, setEnabled };
diff --git a/src/content/actions/find.js b/src/content/actions/find.js
deleted file mode 100644
index e08d7e5..0000000
--- a/src/content/actions/find.js
+++ /dev/null
@@ -1,68 +0,0 @@
-//
-// window.find(aString, aCaseSensitive, aBackwards, aWrapAround,
-// aWholeWord, aSearchInFrames);
-//
-// 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 consoleFrames from '../console-frames';
-
-const find = (string, backwards) => {
- 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);
- if (found) {
- return found;
- }
- window.getSelection().removeAllRanges();
- return window.find(string, caseSensitive, backwards, wrapScan);
-};
-
-const findNext = async(currentKeyword, reset, backwards) => {
- if (reset) {
- window.getSelection().removeAllRanges();
- }
-
- let keyword = currentKeyword;
- if (currentKeyword) {
- browser.runtime.sendMessage({
- type: messages.FIND_SET_KEYWORD,
- keyword: currentKeyword,
- });
- } else {
- keyword = await browser.runtime.sendMessage({
- type: messages.FIND_GET_KEYWORD,
- });
- }
- if (!keyword) {
- return consoleFrames.postError('No previous search keywords');
- }
- let found = find(keyword, backwards);
- if (found) {
- consoleFrames.postInfo('Pattern found: ' + keyword);
- } else {
- consoleFrames.postError('Pattern not found: ' + keyword);
- }
-
- return {
- type: actions.FIND_SET_KEYWORD,
- keyword,
- found,
- };
-};
-
-const next = (currentKeyword, reset) => {
- return findNext(currentKeyword, reset, false);
-};
-
-const prev = (currentKeyword, reset) => {
- return findNext(currentKeyword, reset, true);
-};
-
-export { next, prev };
diff --git a/src/content/actions/find.ts b/src/content/actions/find.ts
new file mode 100644
index 0000000..53e03ae
--- /dev/null
+++ b/src/content/actions/find.ts
@@ -0,0 +1,100 @@
+//
+// window.find(aString, aCaseSensitive, aBackwards, aWrapAround,
+// aWholeWord, aSearchInFrames);
+//
+// NOTE: window.find is not standard API
+// https://developer.mozilla.org/en-US/docs/Web/API/Window/find
+
+import * as messages from '../../shared/messages';
+import * as actions from './index';
+import * as consoleFrames from '../console-frames';
+
+interface MyWindow extends Window {
+ find(
+ aString: string,
+ aCaseSensitive?: boolean,
+ aBackwards?: boolean,
+ aWrapAround?: boolean,
+ aWholeWord?: boolean,
+ aSearchInFrames?: boolean,
+ aShowDialog?: boolean): boolean;
+}
+
+// eslint-disable-next-line no-var, vars-on-top, init-declarations
+declare var window: MyWindow;
+
+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
+
+ // eslint-disable-next-line no-extra-parens
+ let found = window.find(str, caseSensitive, backwards, wrapScan);
+ if (found) {
+ return found;
+ }
+ let sel = window.getSelection();
+ if (sel) {
+ sel.removeAllRanges();
+ }
+
+ // eslint-disable-next-line no-extra-parens
+ return window.find(str, caseSensitive, backwards, wrapScan);
+};
+
+// eslint-disable-next-line max-statements
+const findNext = async(
+ currentKeyword: string, reset: boolean, backwards: boolean,
+): Promise<actions.FindAction> => {
+ if (reset) {
+ let sel = window.getSelection();
+ if (sel) {
+ sel.removeAllRanges();
+ }
+ }
+
+ let keyword = currentKeyword;
+ if (currentKeyword) {
+ browser.runtime.sendMessage({
+ type: messages.FIND_SET_KEYWORD,
+ keyword: currentKeyword,
+ });
+ } else {
+ keyword = await browser.runtime.sendMessage({
+ type: messages.FIND_GET_KEYWORD,
+ });
+ }
+ if (!keyword) {
+ await consoleFrames.postError('No previous search keywords');
+ return { type: actions.NOOP };
+ }
+ let found = find(keyword, backwards);
+ if (found) {
+ consoleFrames.postInfo('Pattern found: ' + keyword);
+ } else {
+ consoleFrames.postError('Pattern not found: ' + keyword);
+ }
+
+ return {
+ type: actions.FIND_SET_KEYWORD,
+ keyword,
+ found,
+ };
+};
+
+const next = (
+ currentKeyword: string, reset: boolean,
+): Promise<actions.FindAction> => {
+ return findNext(currentKeyword, reset, false);
+};
+
+const prev = (
+ currentKeyword: string, reset: boolean,
+): Promise<actions.FindAction> => {
+ return findNext(currentKeyword, reset, true);
+};
+
+export { next, prev };
diff --git a/src/content/actions/follow-controller.js b/src/content/actions/follow-controller.ts
index 006b248..115b3b6 100644
--- a/src/content/actions/follow-controller.js
+++ 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.js b/src/content/actions/index.js
deleted file mode 100644
index 0a16fdf..0000000
--- a/src/content/actions/index.js
+++ /dev/null
@@ -1,31 +0,0 @@
-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',
-};
diff --git a/src/content/actions/index.ts b/src/content/actions/index.ts
new file mode 100644
index 0000000..8aa9c23
--- /dev/null
+++ b/src/content/actions/index.ts
@@ -0,0 +1,122 @@
+import Redux from 'redux';
+import Settings from '../../shared/Settings';
+import * as keyUtils from '../../shared/utils/keys';
+
+// 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;
+ settings: Settings,
+}
+
+export interface InputKeyPressAction extends Redux.Action {
+ type: typeof INPUT_KEY_PRESS;
+ key: keyUtils.Key;
+}
+
+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.js b/src/content/actions/input.js
deleted file mode 100644
index 465a486..0000000
--- a/src/content/actions/input.js
+++ /dev/null
@@ -1,16 +0,0 @@
-import actions from 'content/actions';
-
-const keyPress = (key) => {
- return {
- type: actions.INPUT_KEY_PRESS,
- key,
- };
-};
-
-const clearKeys = () => {
- return {
- type: actions.INPUT_CLEAR_KEYS
- };
-};
-
-export { keyPress, clearKeys };
diff --git a/src/content/actions/input.ts b/src/content/actions/input.ts
new file mode 100644
index 0000000..1df6452
--- /dev/null
+++ b/src/content/actions/input.ts
@@ -0,0 +1,17 @@
+import * as actions from './index';
+import * as keyUtils from '../../shared/utils/keys';
+
+const keyPress = (key: keyUtils.Key): actions.InputAction => {
+ return {
+ type: actions.INPUT_KEY_PRESS,
+ key,
+ };
+};
+
+const clearKeys = (): actions.InputAction => {
+ return {
+ type: actions.INPUT_CLEAR_KEYS
+ };
+};
+
+export { keyPress, clearKeys };
diff --git a/src/content/actions/mark.js b/src/content/actions/mark.js
deleted file mode 100644
index 712a811..0000000
--- a/src/content/actions/mark.js
+++ /dev/null
@@ -1,46 +0,0 @@
-import actions from 'content/actions';
-import messages from 'shared/messages';
-
-const startSet = () => {
- return { type: actions.MARK_START_SET };
-};
-
-const startJump = () => {
- return { type: actions.MARK_START_JUMP };
-};
-
-const cancel = () => {
- return { type: actions.MARK_CANCEL };
-};
-
-const setLocal = (key, x, y) => {
- return {
- type: actions.MARK_SET_LOCAL,
- key,
- x,
- y,
- };
-};
-
-const setGlobal = (key, x, y) => {
- browser.runtime.sendMessage({
- type: messages.MARK_SET_GLOBAL,
- key,
- x,
- y,
- });
- return { type: '' };
-};
-
-const jumpGlobal = (key) => {
- browser.runtime.sendMessage({
- type: messages.MARK_JUMP_GLOBAL,
- key,
- });
- return { type: '' };
-};
-
-export {
- startSet, startJump, cancel, setLocal,
- setGlobal, jumpGlobal,
-};
diff --git a/src/content/actions/mark.ts b/src/content/actions/mark.ts
new file mode 100644
index 0000000..5eb9554
--- /dev/null
+++ b/src/content/actions/mark.ts
@@ -0,0 +1,46 @@
+import * as actions from './index';
+import * as messages from '../../shared/messages';
+
+const startSet = (): actions.MarkAction => {
+ return { type: actions.MARK_START_SET };
+};
+
+const startJump = (): actions.MarkAction => {
+ return { type: actions.MARK_START_JUMP };
+};
+
+const cancel = (): actions.MarkAction => {
+ return { type: actions.MARK_CANCEL };
+};
+
+const setLocal = (key: string, x: number, y: number): actions.MarkAction => {
+ return {
+ type: actions.MARK_SET_LOCAL,
+ 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: actions.NOOP };
+};
+
+const jumpGlobal = (key: string): actions.MarkAction => {
+ browser.runtime.sendMessage({
+ type: messages.MARK_JUMP_GLOBAL,
+ key,
+ });
+ return { type: actions.NOOP };
+};
+
+export {
+ startSet, startJump, cancel, setLocal,
+ setGlobal, jumpGlobal,
+};
diff --git a/src/content/actions/operation.js b/src/content/actions/operation.ts
index ed9b2cf..41e080b 100644
--- a/src/content/actions/operation.js
+++ b/src/content/actions/operation.ts
@@ -1,18 +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';
// eslint-disable-next-line complexity, max-lines-per-function
-const exec = (operation, settings, addonEnabled) => {
- let smoothscroll = settings.properties.smoothscroll ||
- properties.defaults.smoothscroll;
+const exec = (
+ operation: operations.Operation,
+ settings: any,
+ addonEnabled: boolean,
+): Promise<actions.Action> | actions.Action => {
+ let smoothscroll = settings.properties.smoothscroll;
switch (operation.type) {
case operations.ADDON_ENABLE:
return addonActions.enable();
@@ -98,7 +101,7 @@ const exec = (operation, settings, addonEnabled) => {
operation,
});
}
- return { type: '' };
+ return { type: actions.NOOP };
};
export { exec };
diff --git a/src/content/actions/setting.js b/src/content/actions/setting.js
deleted file mode 100644
index 1c15dd7..0000000
--- a/src/content/actions/setting.js
+++ /dev/null
@@ -1,37 +0,0 @@
-import actions from 'content/actions';
-import * as keyUtils from 'shared/utils/keys';
-import operations from 'shared/operations';
-import messages from 'shared/messages';
-
-const reservedKeymaps = {
- '<Esc>': { type: operations.CANCEL },
- '<C-[>': { type: operations.CANCEL },
-};
-
-const set = (value) => {
- let entries = [];
- if (value.keymaps) {
- let keymaps = { ...value.keymaps, ...reservedKeymaps };
- entries = Object.entries(keymaps).map((entry) => {
- return [
- keyUtils.fromMapKeys(entry[0]),
- entry[1],
- ];
- });
- }
-
- return {
- type: actions.SETTING_SET,
- value: { ...value,
- keymaps: entries, }
- };
-};
-
-const load = async() => {
- let settings = await browser.runtime.sendMessage({
- type: messages.SETTINGS_QUERY,
- });
- return set(settings);
-};
-
-export { set, load };
diff --git a/src/content/actions/setting.ts b/src/content/actions/setting.ts
new file mode 100644
index 0000000..92f8559
--- /dev/null
+++ b/src/content/actions/setting.ts
@@ -0,0 +1,28 @@
+import * as actions from './index';
+import * as operations from '../../shared/operations';
+import * as messages from '../../shared/messages';
+import Settings, { Keymaps } from '../../shared/Settings';
+
+const reservedKeymaps: Keymaps = {
+ '<Esc>': { type: operations.CANCEL },
+ '<C-[>': { type: operations.CANCEL },
+};
+
+const set = (settings: Settings): actions.SettingAction => {
+ return {
+ type: actions.SETTING_SET,
+ settings: {
+ ...settings,
+ keymaps: { ...settings.keymaps, ...reservedKeymaps },
+ }
+ };
+};
+
+const load = async(): Promise<actions.SettingAction> => {
+ let settings = await browser.runtime.sendMessage({
+ type: messages.SETTINGS_QUERY,
+ });
+ return set(settings);
+};
+
+export { set, load };