{
- if (e.keyCode !== Key.ESC) {
+ if (e.key !== "Escape") {
e.stopPropagation()
}
}
@@ -15,7 +14,8 @@ BooleanOption.propTypes = {
value: PropTypes.bool.isRequired,
onChange: PropTypes.func.isRequired,
}
-function BooleanOption({ value, onChange, ...props }) {
+
+function BooleanOption({value, onChange, ...props}) {
return (
@@ -34,7 +34,8 @@ StringOption.propTypes = {
value: PropTypes.string,
onChange: PropTypes.func.isRequired,
}
-function StringOption({ value, onChange, ...props }) {
+
+function StringOption({value, onChange, ...props}) {
return (
)
}
+
function Optional(Component) {
- return function ({ onChange, ...props }) {
+ return function ({onChange, ...props}) {
return onChange(x ? x : null)}
{...props}
@@ -56,7 +58,8 @@ NumberOption.propTypes = {
value: PropTypes.number.isRequired,
onChange: PropTypes.func.isRequired,
}
-function NumberOption({ value, onChange, ...props }) {
+
+function NumberOption({value, onChange, ...props}) {
return (
onChange(e.target.value)}
value={value}
{...props}
>
- { choices.map(
+ {choices.map(
choice => (
{choice}
)
@@ -90,7 +94,8 @@ StringSequenceOption.propTypes = {
value: PropTypes.arrayOf(PropTypes.string).isRequired,
onChange: PropTypes.func.isRequired,
}
-function StringSequenceOption({ value, onChange, ...props }) {
+
+function StringSequenceOption({value, onChange, ...props}) {
const height = Math.max(value.length, 1)
return
+ return
+
+
}
+
export default connect(
- (state, { name }) => ({
+ (state, {name}) => ({
...state.options_meta[name],
...state.ui.optionsEditor[name]
}),
- (dispatch, { name }) => ({
+ (dispatch, {name}) => ({
onChange: value => dispatch(updateOptions(name, value))
})
)(PureOption)
diff --git a/web/src/js/components/common/ToggleInputButton.tsx b/web/src/js/components/common/ToggleInputButton.tsx
deleted file mode 100644
index 510064491..000000000
--- a/web/src/js/components/common/ToggleInputButton.tsx
+++ /dev/null
@@ -1,55 +0,0 @@
-import React, { Component } from 'react'
-import classnames from 'classnames'
-import { Key } from '../../utils'
-
-type ToggleInputButtonProps = {
- name: string,
- txt: string,
- onToggleChanged: Function,
- checked: boolean,
- placeholder: string,
- inputType: string,
-}
-
-type ToggleInputButtonState = {
- txt: string,
-}
-
-export default class ToggleInputButton extends Component {
- constructor(props) {
- super(props)
- this.state = { txt: props.txt || '' }
- }
-
- onKeyDown(e) {
- e.stopPropagation()
- if (e.keyCode === Key.ENTER) {
- this.props.onToggleChanged(this.state.txt)
- }
- }
-
- render() {
- const {checked, onToggleChanged, name, inputType, placeholder} = this.props
- return (
-
-
onToggleChanged(this.state.txt)}>
-
-
-
- {name}
-
-
-
this.setState({ txt: e.target.value })}
- onKeyDown={e => this.onKeyDown(e)}
- />
-
- )
- }
-}
diff --git a/web/src/js/components/contentviews/useContent.ts b/web/src/js/components/contentviews/useContent.tsx
similarity index 100%
rename from web/src/js/components/contentviews/useContent.ts
rename to web/src/js/components/contentviews/useContent.tsx
diff --git a/web/src/js/components/editors/ValueEditor.tsx b/web/src/js/components/editors/ValueEditor.tsx
index 88b427c1b..694a361fa 100644
--- a/web/src/js/components/editors/ValueEditor.tsx
+++ b/web/src/js/components/editors/ValueEditor.tsx
@@ -1,8 +1,6 @@
import React, {Component} from 'react'
import classnames from 'classnames'
-import {Key} from '../../utils'
-
export interface ValueEditorProps {
content: string
onEditDone: (newVal: string) => void
@@ -157,13 +155,13 @@ export default class ValueEditor extends Component {
onKeyDown = (e: React.KeyboardEvent) => {
EVENT_DEBUG && console.debug("keydown", e)
e.stopPropagation()
- switch (e.keyCode) {
- case Key.ESC:
+ switch (e.key) {
+ case "Escape":
e.preventDefault()
this.resetValue()
this.finishEditing()
break
- case Key.ENTER:
+ case "Enter":
if (!e.shiftKey) {
e.preventDefault()
this.finishEditing()
diff --git a/web/src/js/components/helpers/AutoScroll.js b/web/src/js/components/helpers/AutoScroll.tsx
similarity index 94%
rename from web/src/js/components/helpers/AutoScroll.js
rename to web/src/js/components/helpers/AutoScroll.tsx
index 1d4d90c58..55430fe3d 100644
--- a/web/src/js/components/helpers/AutoScroll.js
+++ b/web/src/js/components/helpers/AutoScroll.tsx
@@ -1,7 +1,7 @@
import React from "react";
import ReactDOM from "react-dom";
-const symShouldStick = Symbol("shouldStick");
+const symShouldStick = Symbol("shouldStick") as any;
const isAtBottom = v => v.scrollTop + v.clientHeight === v.scrollHeight;
export default Component => Object.assign(class AutoScrollWrapper extends Component {
diff --git a/web/src/js/components/helpers/VirtualScroll.js b/web/src/js/components/helpers/VirtualScroll.tsx
similarity index 85%
rename from web/src/js/components/helpers/VirtualScroll.js
rename to web/src/js/components/helpers/VirtualScroll.tsx
index d9b310034..f0b15679b 100644
--- a/web/src/js/components/helpers/VirtualScroll.js
+++ b/web/src/js/components/helpers/VirtualScroll.tsx
@@ -18,7 +18,23 @@
* - {number} paddingTop
* - {number} paddingBottom
*/
-export function calcVScroll(opts) {
+
+type VScrollArgs = {
+ itemCount: number
+ rowHeight: number
+ viewportTop: number
+ viewportHeight: number
+ itemHeights?: number[]
+}
+
+export type VScroll = {
+ start: number
+ end: number
+ paddingTop: number
+ paddingBottom: number
+}
+
+export function calcVScroll(opts: VScrollArgs | undefined = undefined) {
if (!opts) {
return { start: 0, end: 0, paddingTop: 0, paddingBottom: 0 };
}
diff --git a/web/src/js/ducks/commandBar.ts b/web/src/js/ducks/commandBar.ts
index d073c4df3..84429e999 100644
--- a/web/src/js/ducks/commandBar.ts
+++ b/web/src/js/ducks/commandBar.ts
@@ -1,5 +1,3 @@
-import {Reducer} from "redux";
-
export const TOGGLE_VISIBILITY = 'COMMANDBAR_TOGGLE_VISIBILITY'
interface CommandBarState {
@@ -10,7 +8,7 @@ export const defaultState: CommandBarState = {
visible: false,
};
-const reducer: Reducer = (state = defaultState, action): CommandBarState => {
+export default function reducer(state = defaultState, action): CommandBarState {
switch (action.type) {
case TOGGLE_VISIBILITY:
return {
@@ -22,8 +20,7 @@ const reducer: Reducer = (state = defaultState, action): Comman
return state
}
}
-export default reducer
export function toggleVisibility() {
- return { type: TOGGLE_VISIBILITY }
+ return {type: TOGGLE_VISIBILITY}
}
diff --git a/web/src/js/ducks/conf.ts b/web/src/js/ducks/conf.ts
index 187e103dc..0ce9e802c 100644
--- a/web/src/js/ducks/conf.ts
+++ b/web/src/js/ducks/conf.ts
@@ -2,7 +2,6 @@
* Conf houses properties about the current mitmproxy instance that are not options,
* e.g. the list of available content views or the current version.
*/
-import {Reducer} from "redux";
interface ConfState {
static: boolean
@@ -17,7 +16,6 @@ export const defaultState: ConfState = window.MITMWEB_CONF || {
contentViews: ["Auto", "Raw"],
};
-const reducer: Reducer = (state = defaultState, action): ConfState => {
+export default function reducer(state = defaultState, action): ConfState {
return state
}
-export default reducer
diff --git a/web/src/js/ducks/connection.ts b/web/src/js/ducks/connection.ts
index f650573f9..c9d41987b 100644
--- a/web/src/js/ducks/connection.ts
+++ b/web/src/js/ducks/connection.ts
@@ -1,5 +1,3 @@
-import {Reducer} from "redux";
-
export enum ConnectionState {
INIT = "CONNECTION_INIT",
FETCHING = "CONNECTION_FETCHING", // WebSocket is established, but still fetching resources.
@@ -19,7 +17,7 @@ const defaultState: ConnState = {
message: undefined,
}
-const reducer: Reducer = (state = defaultState, action) => {
+export default function reducer(state = defaultState, action): ConnState {
switch (action.type) {
case ConnectionState.ESTABLISHED:
case ConnectionState.FETCHING:
@@ -34,7 +32,6 @@ const reducer: Reducer = (state = defaultState, action) => {
return state
}
}
-export default reducer
export function startFetching() {
return {type: ConnectionState.FETCHING}
diff --git a/web/src/js/ducks/eventLog.ts b/web/src/js/ducks/eventLog.ts
index 414d7e82e..fb69bf946 100644
--- a/web/src/js/ducks/eventLog.ts
+++ b/web/src/js/ducks/eventLog.ts
@@ -7,7 +7,7 @@ export const TOGGLE_FILTER = 'EVENTS_TOGGLE_FILTER'
type LogLevel = 'debug' | 'info' | 'web' | 'warn' | 'error';
-interface EventLogItem extends store.Item {
+export interface EventLogItem extends store.Item {
message: string
level: LogLevel
}
diff --git a/web/src/js/ducks/flows.ts b/web/src/js/ducks/flows.ts
index 02377295d..c636ddbf7 100644
--- a/web/src/js/ducks/flows.ts
+++ b/web/src/js/ducks/flows.ts
@@ -28,7 +28,7 @@ export interface FlowsState extends store.State {
selected: string[],
}
-const defaultState: FlowsState = {
+export const defaultState: FlowsState = {
highlight: undefined,
filter: undefined,
sort: {column: undefined, desc: false},
@@ -36,7 +36,7 @@ const defaultState: FlowsState = {
...store.defaultState
}
-export default function reduce(state: FlowsState = defaultState, action): FlowsState {
+export default function reducer(state: FlowsState = defaultState, action): FlowsState {
switch (action.type) {
case ADD:
diff --git a/web/src/js/ducks/options.ts b/web/src/js/ducks/options.ts
index 28641860a..76f5728ab 100644
--- a/web/src/js/ducks/options.ts
+++ b/web/src/js/ducks/options.ts
@@ -1,7 +1,5 @@
import {fetchApi} from "../utils"
import * as optionsEditorActions from "./ui/optionsEditor"
-import _ from "lodash"
-import {Reducer} from "redux";
import {defaultState, Option, OptionsState} from "./_options_gen";
import {AppThunk} from "./index";
@@ -11,8 +9,7 @@ export const REQUEST_UPDATE = 'REQUEST_UPDATE'
export {Option, defaultState}
-const reducer: Reducer = (state = defaultState, action) => {
-
+export default function reducer(state = defaultState, action): OptionsState {
switch (action.type) {
case RECEIVE:
let s = {};
@@ -34,7 +31,6 @@ const reducer: Reducer = (state = defaultState, action) => {
return state
}
}
-export default reducer
export async function pureSendUpdate(option: Option, value, dispatch) {
try {
diff --git a/web/src/js/ducks/ui/flow.ts b/web/src/js/ducks/ui/flow.ts
index 8b2d6d91b..55b8359c5 100644
--- a/web/src/js/ducks/ui/flow.ts
+++ b/web/src/js/ducks/ui/flow.ts
@@ -1,5 +1,3 @@
-import {Reducer} from "redux";
-
export const
SET_TAB = "UI_FLOWVIEW_SET_TAB",
SET_CONTENT_VIEW_FOR = "SET_CONTENT_VIEW_FOR"
@@ -15,8 +13,7 @@ export const defaultState: UiFlowState = {
contentViewFor: {},
}
-const reducer: Reducer = (state = defaultState, action): UiFlowState => {
-
+export default function reducer(state = defaultState, action): UiFlowState {
switch (action.type) {
case SET_CONTENT_VIEW_FOR:
@@ -38,7 +35,6 @@ const reducer: Reducer = (state = defaultState, action): UiFlowStat
return state
}
}
-export default reducer;
export function selectTab(tab) {
return {type: SET_TAB, tab}
diff --git a/web/src/js/ducks/ui/keyboard.js b/web/src/js/ducks/ui/keyboard.tsx
similarity index 53%
rename from web/src/js/ducks/ui/keyboard.js
rename to web/src/js/ducks/ui/keyboard.tsx
index 2c0693da3..4297aace3 100644
--- a/web/src/js/ducks/ui/keyboard.js
+++ b/web/src/js/ducks/ui/keyboard.tsx
@@ -1,130 +1,133 @@
-import { Key } from "../../utils"
-import { selectTab } from "./flow"
+import {selectTab} from "./flow"
import * as flowsActions from "../flows"
import * as modalActions from "./modal"
import {tabsForFlow} from "../../components/FlowView";
-export function onKeyDown(e) {
+export function onKeyDown(e: KeyboardEvent) {
//console.debug("onKeyDown", e)
if (e.ctrlKey || e.metaKey) {
return () => {
}
}
- let key = e.keyCode,
- shiftKey = e.shiftKey
+ const key = e.key;
e.preventDefault()
return (dispatch, getState) => {
const flows = getState().flows,
- flow = flows.byId[getState().flows.selected[0]]
+ flow = flows.byId[getState().flows.selected[0]]
switch (key) {
- case Key.K:
- case Key.UP:
+ case "k":
+ case "ArrowUp":
dispatch(flowsActions.selectRelative(flows, -1))
break
- case Key.J:
- case Key.DOWN:
+ case "j":
+ case "ArrowDown":
dispatch(flowsActions.selectRelative(flows, +1))
break
- case Key.SPACE:
- case Key.PAGE_DOWN:
+ case " ":
+ case "PageDown":
dispatch(flowsActions.selectRelative(flows, +10))
break
- case Key.PAGE_UP:
+ case "PageUp":
dispatch(flowsActions.selectRelative(flows, -10))
break
- case Key.END:
+ case "End":
dispatch(flowsActions.selectRelative(flows, +1e10))
break
- case Key.HOME:
+ case "Home":
dispatch(flowsActions.selectRelative(flows, -1e10))
break
- case Key.ESC:
- if(getState().ui.modal.activeModal){
+ case "Escape":
+ if (getState().ui.modal.activeModal) {
dispatch(modalActions.hideModal())
} else {
- dispatch(flowsActions.select(null))
+ dispatch(flowsActions.select(undefined))
}
break
- case Key.LEFT: {
+ case "ArrowLeft": {
if (!flow) break
- let tabs = tabsForFlow(flow),
+ let tabs = tabsForFlow(flow),
currentTab = getState().ui.flow.tab,
- nextTab = tabs[(tabs.indexOf(currentTab) - 1 + tabs.length) % tabs.length]
+ nextTab = tabs[(tabs.indexOf(currentTab) - 1 + tabs.length) % tabs.length]
dispatch(selectTab(nextTab))
break
}
- case Key.TAB:
- case Key.RIGHT: {
+ case "Tab":
+ case "ArrowRight": {
if (!flow) break
- let tabs = tabsForFlow(flow),
+ let tabs = tabsForFlow(flow),
currentTab = getState().ui.flow.tab,
- nextTab = tabs[(tabs.indexOf(currentTab) + 1) % tabs.length]
+ nextTab = tabs[(tabs.indexOf(currentTab) + 1) % tabs.length]
dispatch(selectTab(nextTab))
break
}
- case Key.D: {
+ case "d": {
if (!flow) {
return
}
- if (shiftKey) {
- dispatch(flowsActions.duplicate(flow))
- } else {
- dispatch(flowsActions.remove(flow))
- }
+ dispatch(flowsActions.remove(flow))
break
}
- case Key.A: {
- if (shiftKey) {
- dispatch(flowsActions.resumeAll())
- } else if (flow && flow.intercepted) {
+ case "D": {
+ if (!flow) {
+ return
+ }
+ dispatch(flowsActions.duplicate(flow))
+ break
+ }
+ case "a": {
+ if (flow && flow.intercepted) {
dispatch(flowsActions.resume(flow))
}
break
}
+ case "A": {
+ dispatch(flowsActions.resumeAll())
+ break
+ }
- case Key.R: {
- if (!shiftKey && flow) {
+ case "r": {
+ if (flow) {
dispatch(flowsActions.replay(flow))
}
break
}
- case Key.V: {
- if (!shiftKey && flow && flow.modified) {
+ case "v": {
+ if (flow && flow.modified) {
dispatch(flowsActions.revert(flow))
}
break
}
- case Key.X: {
- if (shiftKey) {
- dispatch(flowsActions.killAll())
- } else if (flow && flow.intercepted) {
+ case "x": {
+ if (flow && flow.intercepted) {
dispatch(flowsActions.kill(flow))
}
break
}
- case Key.Z: {
- if (!shiftKey) {
- dispatch(flowsActions.clear())
- }
+ case "X": {
+ dispatch(flowsActions.killAll())
break
}
+ case "z": {
+ dispatch(flowsActions.clear())
+ break
+ }
default:
return
diff --git a/web/src/js/ducks/utils/store.ts b/web/src/js/ducks/utils/store.ts
index 7681fecf9..cd7b521fe 100644
--- a/web/src/js/ducks/utils/store.ts
+++ b/web/src/js/ducks/utils/store.ts
@@ -52,7 +52,7 @@ export const defaultState = {
* }
*
*/
-export function reduce(state: State = defaultState, action) {
+export function reduce(state: State = defaultState, action): State {
let {byId, list, listIndex, view, viewIndex} = state
diff --git a/web/src/js/utils.ts b/web/src/js/utils.ts
index ec7868dfc..30d2af60d 100644
--- a/web/src/js/utils.ts
+++ b/web/src/js/utils.ts
@@ -5,28 +5,6 @@ import * as React from 'react'
window._ = _;
window.React = React;
-export var Key = {
- UP: 38,
- DOWN: 40,
- PAGE_UP: 33,
- PAGE_DOWN: 34,
- HOME: 36,
- END: 35,
- LEFT: 37,
- RIGHT: 39,
- ENTER: 13,
- ESC: 27,
- TAB: 9,
- SPACE: 32,
- BACKSPACE: 8,
- SHIFT: 16
-};
-// Add A-Z
-for (var i = 65; i <= 90; i++) {
- Key[String.fromCharCode(i)] = i;
-}
-
-
export var formatSize = function (bytes) {
if (bytes === 0)
return "0";
@@ -64,7 +42,7 @@ export var formatTimeStamp = function (
) {
let utc = new Date(seconds * 1000);
let ts = utc.toISOString().replace("T", " ").replace("Z", "");
- if(!milliseconds)
+ if (!milliseconds)
ts = ts.slice(0, -4);
return ts;
};