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/shared/operations.ts | |
parent | 685f2b7b69218b06b5bb676069e35f79c5048c9b (diff) | |
parent | 75abd90ecb8201ad845b266f96220d8adfe19b2d (diff) |
Merge pull request #749 from ueokande/qa-0.28
QA 0.28
Diffstat (limited to 'src/shared/operations.ts')
-rw-r--r-- | src/shared/operations.ts | 480 |
1 files changed, 246 insertions, 234 deletions
diff --git a/src/shared/operations.ts b/src/shared/operations.ts index beca7b9..3544502 100644 --- a/src/shared/operations.ts +++ b/src/shared/operations.ts @@ -1,85 +1,85 @@ // Hide console; or cancel some user actions -export const CANCEL = 'cancel'; +export const CANCEL = "cancel"; // Addons -export const ADDON_ENABLE = 'addon.enable'; -export const ADDON_DISABLE = 'addon.disable'; -export const ADDON_TOGGLE_ENABLED = 'addon.toggle.enabled'; +export const ADDON_ENABLE = "addon.enable"; +export const ADDON_DISABLE = "addon.disable"; +export const ADDON_TOGGLE_ENABLED = "addon.toggle.enabled"; // Command -export const COMMAND_SHOW = 'command.show'; -export const COMMAND_SHOW_OPEN = 'command.show.open'; -export const COMMAND_SHOW_TABOPEN = 'command.show.tabopen'; -export const COMMAND_SHOW_WINOPEN = 'command.show.winopen'; -export const COMMAND_SHOW_BUFFER = 'command.show.buffer'; -export const COMMAND_SHOW_ADDBOOKMARK = 'command.show.addbookmark'; +export const COMMAND_SHOW = "command.show"; +export const COMMAND_SHOW_OPEN = "command.show.open"; +export const COMMAND_SHOW_TABOPEN = "command.show.tabopen"; +export const COMMAND_SHOW_WINOPEN = "command.show.winopen"; +export const COMMAND_SHOW_BUFFER = "command.show.buffer"; +export const COMMAND_SHOW_ADDBOOKMARK = "command.show.addbookmark"; // Scrolls -export const SCROLL_VERTICALLY = 'scroll.vertically'; -export const SCROLL_HORIZONALLY = 'scroll.horizonally'; -export const SCROLL_PAGES = 'scroll.pages'; -export const SCROLL_TOP = 'scroll.top'; -export const SCROLL_BOTTOM = 'scroll.bottom'; -export const SCROLL_HOME = 'scroll.home'; -export const SCROLL_END = 'scroll.end'; +export const SCROLL_VERTICALLY = "scroll.vertically"; +export const SCROLL_HORIZONALLY = "scroll.horizonally"; +export const SCROLL_PAGES = "scroll.pages"; +export const SCROLL_TOP = "scroll.top"; +export const SCROLL_BOTTOM = "scroll.bottom"; +export const SCROLL_HOME = "scroll.home"; +export const SCROLL_END = "scroll.end"; // Follows -export const FOLLOW_START = 'follow.start'; +export const FOLLOW_START = "follow.start"; // Navigations -export const NAVIGATE_HISTORY_PREV = 'navigate.history.prev'; -export const NAVIGATE_HISTORY_NEXT = 'navigate.history.next'; -export const NAVIGATE_LINK_PREV = 'navigate.link.prev'; -export const NAVIGATE_LINK_NEXT = 'navigate.link.next'; -export const NAVIGATE_PARENT = 'navigate.parent'; -export const NAVIGATE_ROOT = 'navigate.root'; +export const NAVIGATE_HISTORY_PREV = "navigate.history.prev"; +export const NAVIGATE_HISTORY_NEXT = "navigate.history.next"; +export const NAVIGATE_LINK_PREV = "navigate.link.prev"; +export const NAVIGATE_LINK_NEXT = "navigate.link.next"; +export const NAVIGATE_PARENT = "navigate.parent"; +export const NAVIGATE_ROOT = "navigate.root"; // Focus -export const FOCUS_INPUT = 'focus.input'; +export const FOCUS_INPUT = "focus.input"; // Page -export const PAGE_SOURCE = 'page.source'; -export const PAGE_HOME = 'page.home'; +export const PAGE_SOURCE = "page.source"; +export const PAGE_HOME = "page.home"; // Tabs -export const TAB_CLOSE = 'tabs.close'; -export const TAB_CLOSE_FORCE = 'tabs.close.force'; -export const TAB_CLOSE_RIGHT = 'tabs.close.right'; -export const TAB_REOPEN = 'tabs.reopen'; -export const TAB_PREV = 'tabs.prev'; -export const TAB_NEXT = 'tabs.next'; -export const TAB_FIRST = 'tabs.first'; -export const TAB_LAST = 'tabs.last'; -export const TAB_PREV_SEL = 'tabs.prevsel'; -export const TAB_RELOAD = 'tabs.reload'; -export const TAB_PIN = 'tabs.pin'; -export const TAB_UNPIN = 'tabs.unpin'; -export const TAB_TOGGLE_PINNED = 'tabs.pin.toggle'; -export const TAB_DUPLICATE = 'tabs.duplicate'; +export const TAB_CLOSE = "tabs.close"; +export const TAB_CLOSE_FORCE = "tabs.close.force"; +export const TAB_CLOSE_RIGHT = "tabs.close.right"; +export const TAB_REOPEN = "tabs.reopen"; +export const TAB_PREV = "tabs.prev"; +export const TAB_NEXT = "tabs.next"; +export const TAB_FIRST = "tabs.first"; +export const TAB_LAST = "tabs.last"; +export const TAB_PREV_SEL = "tabs.prevsel"; +export const TAB_RELOAD = "tabs.reload"; +export const TAB_PIN = "tabs.pin"; +export const TAB_UNPIN = "tabs.unpin"; +export const TAB_TOGGLE_PINNED = "tabs.pin.toggle"; +export const TAB_DUPLICATE = "tabs.duplicate"; // Zooms -export const ZOOM_IN = 'zoom.in'; -export const ZOOM_OUT = 'zoom.out'; -export const ZOOM_NEUTRAL = 'zoom.neutral'; +export const ZOOM_IN = "zoom.in"; +export const ZOOM_OUT = "zoom.out"; +export const ZOOM_NEUTRAL = "zoom.neutral"; // Url yank/paste -export const URLS_YANK = 'urls.yank'; -export const URLS_PASTE = 'urls.paste'; +export const URLS_YANK = "urls.yank"; +export const URLS_PASTE = "urls.paste"; // Find -export const FIND_START = 'find.start'; -export const FIND_NEXT = 'find.next'; -export const FIND_PREV = 'find.prev'; +export const FIND_START = "find.start"; +export const FIND_NEXT = "find.next"; +export const FIND_PREV = "find.prev"; // Mark -export const MARK_SET_PREFIX = 'mark.set.prefix'; -export const MARK_JUMP_PREFIX = 'mark.jump.prefix'; +export const MARK_SET_PREFIX = "mark.set.prefix"; +export const MARK_JUMP_PREFIX = "mark.jump.prefix"; // Repeat -export const REPEAT_LAST = 'repeat.last'; +export const REPEAT_LAST = "repeat.last"; // Internal -export const INTERNAL_OPEN_URL = 'internal.open.url'; +export const INTERNAL_OPEN_URL = "internal.open.url"; export interface CancelOperation { type: typeof CANCEL; @@ -201,7 +201,7 @@ export interface PageHomeOperation { export interface TabCloseOperation { type: typeof TAB_CLOSE; - select?: 'left' | 'right'; + select?: "left" | "right"; } export interface TabCloseForceOperation { @@ -311,65 +311,67 @@ export interface InternalOpenUrl { } export type Operation = - CancelOperation | - AddonEnableOperation | - AddonDisableOperation | - AddonToggleEnabledOperation | - CommandShowOperation | - CommandShowOpenOperation | - CommandShowTabopenOperation | - CommandShowWinopenOperation | - CommandShowBufferOperation | - CommandShowAddbookmarkOperation | - ScrollVerticallyOperation | - ScrollHorizonallyOperation | - ScrollPagesOperation | - ScrollTopOperation | - ScrollBottomOperation | - ScrollHomeOperation | - ScrollEndOperation | - FollowStartOperation | - NavigateHistoryPrevOperation | - NavigateHistoryNextOperation | - NavigateLinkPrevOperation | - NavigateLinkNextOperation | - NavigateParentOperation | - NavigateRootOperation | - FocusInputOperation | - PageSourceOperation | - PageHomeOperation | - TabCloseOperation | - TabCloseForceOperation | - TabCloseRightOperation | - TabReopenOperation | - TabPrevOperation | - TabNextOperation | - TabFirstOperation | - TabLastOperation | - TabPrevSelOperation | - TabReloadOperation | - TabPinOperation | - TabUnpinOperation | - TabTogglePinnedOperation | - TabDuplicateOperation | - ZoomInOperation | - ZoomOutOperation | - ZoomNeutralOperation | - UrlsYankOperation | - UrlsPasteOperation | - FindStartOperation | - FindNextOperation | - FindPrevOperation | - MarkSetPrefixOperation | - MarkJumpPrefixOperation | - RepeatLastOperation | - InternalOpenUrl; + | CancelOperation + | AddonEnableOperation + | AddonDisableOperation + | AddonToggleEnabledOperation + | CommandShowOperation + | CommandShowOpenOperation + | CommandShowTabopenOperation + | CommandShowWinopenOperation + | CommandShowBufferOperation + | CommandShowAddbookmarkOperation + | ScrollVerticallyOperation + | ScrollHorizonallyOperation + | ScrollPagesOperation + | ScrollTopOperation + | ScrollBottomOperation + | ScrollHomeOperation + | ScrollEndOperation + | FollowStartOperation + | NavigateHistoryPrevOperation + | NavigateHistoryNextOperation + | NavigateLinkPrevOperation + | NavigateLinkNextOperation + | NavigateParentOperation + | NavigateRootOperation + | FocusInputOperation + | PageSourceOperation + | PageHomeOperation + | TabCloseOperation + | TabCloseForceOperation + | TabCloseRightOperation + | TabReopenOperation + | TabPrevOperation + | TabNextOperation + | TabFirstOperation + | TabLastOperation + | TabPrevSelOperation + | TabReloadOperation + | TabPinOperation + | TabUnpinOperation + | TabTogglePinnedOperation + | TabDuplicateOperation + | ZoomInOperation + | ZoomOutOperation + | ZoomNeutralOperation + | UrlsYankOperation + | UrlsPasteOperation + | FindStartOperation + | FindNextOperation + | FindPrevOperation + | MarkSetPrefixOperation + | MarkJumpPrefixOperation + | RepeatLastOperation + | InternalOpenUrl; const assertOptionalBoolean = (obj: any, name: string) => { - if (Object.prototype.hasOwnProperty.call(obj, name) && - typeof obj[name] !== 'boolean') { + if ( + Object.prototype.hasOwnProperty.call(obj, name) && + typeof obj[name] !== "boolean" + ) { throw new TypeError( - `Not a boolean parameter: '${name} (${typeof obj[name]})'`, + `Not a boolean parameter: '${name} (${typeof obj[name]})'` ); } }; @@ -377,9 +379,9 @@ const assertOptionalBoolean = (obj: any, name: string) => { const assertOptionalString = (obj: any, name: string, values?: string[]) => { if (Object.prototype.hasOwnProperty.call(obj, name)) { const value = obj[name]; - if (typeof value !== 'string') { + if (typeof value !== "string") { throw new TypeError( - `Not a string parameter: '${name}' (${typeof value})`, + `Not a string parameter: '${name}' (${typeof value})` ); } if (values && values.length && values.indexOf(value) === -1) { @@ -390,147 +392,157 @@ const assertOptionalString = (obj: any, name: string, values?: string[]) => { }; const assertRequiredNumber = (obj: any, name: string) => { - if (!Object.prototype.hasOwnProperty.call(obj, name) || - typeof obj[name] !== 'number') { + if ( + !Object.prototype.hasOwnProperty.call(obj, name) || + typeof obj[name] !== "number" + ) { throw new TypeError(`Missing number parameter: '${name}`); } }; const assertRequiredString = (obj: any, name: string) => { - if (!Object.prototype.hasOwnProperty.call(obj, name) || - typeof obj[name] !== 'string') { + if ( + !Object.prototype.hasOwnProperty.call(obj, name) || + typeof obj[name] !== "string" + ) { throw new TypeError(`Missing string parameter: '${name}`); } }; // eslint-disable-next-line complexity, max-lines-per-function export const valueOf = (o: any): Operation => { - if (!Object.prototype.hasOwnProperty.call(o, 'type')) { + if (!Object.prototype.hasOwnProperty.call(o, "type")) { throw new TypeError(`Missing 'type' field`); } switch (o.type) { - case COMMAND_SHOW_OPEN: - case COMMAND_SHOW_TABOPEN: - case COMMAND_SHOW_WINOPEN: - case COMMAND_SHOW_ADDBOOKMARK: - assertOptionalBoolean(o, 'alter'); - return { type: o.type, alter: Boolean(o.alter) }; - case SCROLL_VERTICALLY: - case SCROLL_HORIZONALLY: - case SCROLL_PAGES: - assertRequiredNumber(o, 'count'); - return { type: o.type, count: Number(o.count) }; - case FOLLOW_START: - assertOptionalBoolean(o, 'newTab'); - assertOptionalBoolean(o, 'background'); - return { - type: FOLLOW_START, - newTab: Boolean(typeof o.newTab === 'undefined' ? false : o.newTab), - background: Boolean(typeof o.background === 'undefined' ? true : o.background), // eslint-disable-line max-len - }; - case PAGE_HOME: - assertOptionalBoolean(o, 'newTab'); - return { - type: PAGE_HOME, - newTab: Boolean(typeof o.newTab === 'undefined' ? false : o.newTab), - }; - case TAB_CLOSE: - assertOptionalString(o, 'select', ['left', 'right']); - return { - type: TAB_CLOSE, - select: (typeof o.select === 'undefined' ? 'right' : o.select), - }; - case TAB_RELOAD: - assertOptionalBoolean(o, 'cache'); - return { - type: TAB_RELOAD, - cache: Boolean(typeof o.cache === 'undefined' ? false : o.cache), - }; - case URLS_PASTE: - assertOptionalBoolean(o, 'newTab'); - return { - type: URLS_PASTE, - newTab: Boolean(typeof o.newTab === 'undefined' ? false : o.newTab), - }; - case INTERNAL_OPEN_URL: - assertOptionalBoolean(o, 'newTab'); - assertOptionalBoolean(o, 'newWindow'); - assertOptionalBoolean(o, 'background'); - assertRequiredString(o, 'url'); - return { - type: INTERNAL_OPEN_URL, - url: o.url, - newTab: Boolean(typeof o.newTab === 'undefined' ? false : o.newTab), - newWindow: Boolean(typeof o.newWindow === 'undefined' ? false : o.newWindow), // eslint-disable-line max-len - background: Boolean(typeof o.background === 'undefined' ? true : o.background), // eslint-disable-line max-len - }; - case CANCEL: - case ADDON_ENABLE: - case ADDON_DISABLE: - case ADDON_TOGGLE_ENABLED: - case COMMAND_SHOW: - case COMMAND_SHOW_BUFFER: - case SCROLL_TOP: - case SCROLL_BOTTOM: - case SCROLL_HOME: - case SCROLL_END: - case NAVIGATE_HISTORY_PREV: - case NAVIGATE_HISTORY_NEXT: - case NAVIGATE_LINK_PREV: - case NAVIGATE_LINK_NEXT: - case NAVIGATE_PARENT: - case NAVIGATE_ROOT: - case FOCUS_INPUT: - case PAGE_SOURCE: - case TAB_CLOSE_FORCE: - case TAB_CLOSE_RIGHT: - case TAB_REOPEN: - case TAB_PREV: - case TAB_NEXT: - case TAB_FIRST: - case TAB_LAST: - case TAB_PREV_SEL: - case TAB_PIN: - case TAB_UNPIN: - case TAB_TOGGLE_PINNED: - case TAB_DUPLICATE: - case ZOOM_IN: - case ZOOM_OUT: - case ZOOM_NEUTRAL: - case URLS_YANK: - case FIND_START: - case FIND_NEXT: - case FIND_PREV: - case MARK_SET_PREFIX: - case MARK_JUMP_PREFIX: - case REPEAT_LAST: - return { type: o.type }; + case COMMAND_SHOW_OPEN: + case COMMAND_SHOW_TABOPEN: + case COMMAND_SHOW_WINOPEN: + case COMMAND_SHOW_ADDBOOKMARK: + assertOptionalBoolean(o, "alter"); + return { type: o.type, alter: Boolean(o.alter) }; + case SCROLL_VERTICALLY: + case SCROLL_HORIZONALLY: + case SCROLL_PAGES: + assertRequiredNumber(o, "count"); + return { type: o.type, count: Number(o.count) }; + case FOLLOW_START: + assertOptionalBoolean(o, "newTab"); + assertOptionalBoolean(o, "background"); + return { + type: FOLLOW_START, + newTab: Boolean(typeof o.newTab === "undefined" ? false : o.newTab), + background: Boolean( + typeof o.background === "undefined" ? true : o.background + ), // eslint-disable-line max-len + }; + case PAGE_HOME: + assertOptionalBoolean(o, "newTab"); + return { + type: PAGE_HOME, + newTab: Boolean(typeof o.newTab === "undefined" ? false : o.newTab), + }; + case TAB_CLOSE: + assertOptionalString(o, "select", ["left", "right"]); + return { + type: TAB_CLOSE, + select: typeof o.select === "undefined" ? "right" : o.select, + }; + case TAB_RELOAD: + assertOptionalBoolean(o, "cache"); + return { + type: TAB_RELOAD, + cache: Boolean(typeof o.cache === "undefined" ? false : o.cache), + }; + case URLS_PASTE: + assertOptionalBoolean(o, "newTab"); + return { + type: URLS_PASTE, + newTab: Boolean(typeof o.newTab === "undefined" ? false : o.newTab), + }; + case INTERNAL_OPEN_URL: + assertOptionalBoolean(o, "newTab"); + assertOptionalBoolean(o, "newWindow"); + assertOptionalBoolean(o, "background"); + assertRequiredString(o, "url"); + return { + type: INTERNAL_OPEN_URL, + url: o.url, + newTab: Boolean(typeof o.newTab === "undefined" ? false : o.newTab), + newWindow: Boolean( + typeof o.newWindow === "undefined" ? false : o.newWindow + ), // eslint-disable-line max-len + background: Boolean( + typeof o.background === "undefined" ? true : o.background + ), // eslint-disable-line max-len + }; + case CANCEL: + case ADDON_ENABLE: + case ADDON_DISABLE: + case ADDON_TOGGLE_ENABLED: + case COMMAND_SHOW: + case COMMAND_SHOW_BUFFER: + case SCROLL_TOP: + case SCROLL_BOTTOM: + case SCROLL_HOME: + case SCROLL_END: + case NAVIGATE_HISTORY_PREV: + case NAVIGATE_HISTORY_NEXT: + case NAVIGATE_LINK_PREV: + case NAVIGATE_LINK_NEXT: + case NAVIGATE_PARENT: + case NAVIGATE_ROOT: + case FOCUS_INPUT: + case PAGE_SOURCE: + case TAB_CLOSE_FORCE: + case TAB_CLOSE_RIGHT: + case TAB_REOPEN: + case TAB_PREV: + case TAB_NEXT: + case TAB_FIRST: + case TAB_LAST: + case TAB_PREV_SEL: + case TAB_PIN: + case TAB_UNPIN: + case TAB_TOGGLE_PINNED: + case TAB_DUPLICATE: + case ZOOM_IN: + case ZOOM_OUT: + case ZOOM_NEUTRAL: + case URLS_YANK: + case FIND_START: + case FIND_NEXT: + case FIND_PREV: + case MARK_SET_PREFIX: + case MARK_JUMP_PREFIX: + case REPEAT_LAST: + return { type: o.type }; } - throw new TypeError('Unknown operation type: ' + o.type); + throw new TypeError("Unknown operation type: " + o.type); }; export const isNRepeatable = (type: string): boolean => { switch (type) { - case SCROLL_VERTICALLY: - case SCROLL_HORIZONALLY: - case SCROLL_PAGES: - case NAVIGATE_HISTORY_PREV: - case NAVIGATE_HISTORY_NEXT: - case NAVIGATE_PARENT: - case TAB_CLOSE: - case TAB_CLOSE_FORCE: - case TAB_CLOSE_RIGHT: - case TAB_REOPEN: - case TAB_PREV: - case TAB_NEXT: - case TAB_DUPLICATE: - case ZOOM_IN: - case ZOOM_OUT: - case URLS_PASTE: - case FIND_NEXT: - case FIND_PREV: - case REPEAT_LAST: - return true; + case SCROLL_VERTICALLY: + case SCROLL_HORIZONALLY: + case SCROLL_PAGES: + case NAVIGATE_HISTORY_PREV: + case NAVIGATE_HISTORY_NEXT: + case NAVIGATE_PARENT: + case TAB_CLOSE: + case TAB_CLOSE_FORCE: + case TAB_CLOSE_RIGHT: + case TAB_REOPEN: + case TAB_PREV: + case TAB_NEXT: + case TAB_DUPLICATE: + case ZOOM_IN: + case ZOOM_OUT: + case URLS_PASTE: + case FIND_NEXT: + case FIND_PREV: + case REPEAT_LAST: + return true; } return false; }; |