From cf9f91b0b4abe2020c544981d6dc2e2e85f4b4bd Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sun, 22 Mar 2015 14:33:42 +0100 Subject: web: upgrade to react 0.13 --- web/src/js/components/common.js | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'web/src/js/components/common.js') diff --git a/web/src/js/components/common.js b/web/src/js/components/common.js index ffaa717f..3ed035ee 100644 --- a/web/src/js/components/common.js +++ b/web/src/js/components/common.js @@ -32,31 +32,43 @@ var StickyHeadMixin = { var Navigation = _.extend({}, ReactRouter.Navigation, { setQuery: function (dict) { - var q = this.context.getCurrentQuery(); + var q = this.context.router.getCurrentQuery(); for(var i in dict){ if(dict.hasOwnProperty(i)){ q[i] = dict[i] || undefined; //falsey values shall be removed. } } q._ = "_"; // workaround for https://github.com/rackt/react-router/pull/957 - this.replaceWith(this.context.getCurrentPath(), this.context.getCurrentParams(), q); + this.replaceWith(this.context.router.getCurrentPath(), this.context.router.getCurrentParams(), q); }, replaceWith: function(routeNameOrPath, params, query) { if(routeNameOrPath === undefined){ - routeNameOrPath = this.context.getCurrentPath(); + routeNameOrPath = this.context.router.getCurrentPath(); } if(params === undefined){ - params = this.context.getCurrentParams(); + params = this.context.router.getCurrentParams(); } if(query === undefined) { - query = this.context.getCurrentQuery(); + query = this.context.router.getCurrentQuery(); } - // FIXME: react-router is just broken. - ReactRouter.Navigation.replaceWith.call(this, routeNameOrPath, params, query); + // FIXME: react-router is just broken, + // we hopefully just need to wait for the next release with https://github.com/rackt/react-router/pull/957. + this.context.router.replaceWith(routeNameOrPath, params, query); + } +}); + +// react-router is fairly good at changing its API regularly. +// We keep the old method for now - if it should turn out that their changes are permanent, +// we may remove this mixin and access react-router directly again. +var State = _.extend({}, ReactRouter.State, { + getQuery: function(){ + return this.context.router.getCurrentQuery(); + }, + getParams: function(){ + return this.context.router.getCurrentParams(); } }); -_.extend(Navigation.contextTypes, ReactRouter.State.contextTypes); var Splitter = React.createClass({ getDefaultProps: function () { @@ -164,7 +176,7 @@ var Splitter = React.createClass({ }); module.exports = { - State: ReactRouter.State, // keep here - react-router is pretty buggy, we may need workarounds in the future. + State: State, Navigation: Navigation, StickyHeadMixin: StickyHeadMixin, AutoScrollMixin: AutoScrollMixin, -- cgit v1.2.3 From 968c7021dfef00c459899520921faf7367e923d9 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Mon, 23 Mar 2015 00:24:56 +0100 Subject: web: add basic edit capability for first line --- web/src/js/components/common.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'web/src/js/components/common.js') diff --git a/web/src/js/components/common.js b/web/src/js/components/common.js index 3ed035ee..956a46d2 100644 --- a/web/src/js/components/common.js +++ b/web/src/js/components/common.js @@ -30,6 +30,13 @@ var StickyHeadMixin = { }; +var ChildFocus = { + contextTypes: { + returnFocus: React.PropTypes.func + } +}; + + var Navigation = _.extend({}, ReactRouter.Navigation, { setQuery: function (dict) { var q = this.context.router.getCurrentQuery(); @@ -176,6 +183,7 @@ var Splitter = React.createClass({ }); module.exports = { + ChildFocus: ChildFocus, State: State, Navigation: Navigation, StickyHeadMixin: StickyHeadMixin, -- cgit v1.2.3 From d65a4b610007c0ca60fa3f9ac9df06e74d6beb99 Mon Sep 17 00:00:00 2001 From: vzvu3k6k Date: Fri, 27 Mar 2015 04:18:02 +0900 Subject: web: upgrade to react-router 0.13.2 --- web/src/js/components/common.js | 3 --- 1 file changed, 3 deletions(-) (limited to 'web/src/js/components/common.js') diff --git a/web/src/js/components/common.js b/web/src/js/components/common.js index 956a46d2..ba4c93c2 100644 --- a/web/src/js/components/common.js +++ b/web/src/js/components/common.js @@ -45,7 +45,6 @@ var Navigation = _.extend({}, ReactRouter.Navigation, { q[i] = dict[i] || undefined; //falsey values shall be removed. } } - q._ = "_"; // workaround for https://github.com/rackt/react-router/pull/957 this.replaceWith(this.context.router.getCurrentPath(), this.context.router.getCurrentParams(), q); }, replaceWith: function(routeNameOrPath, params, query) { @@ -59,8 +58,6 @@ var Navigation = _.extend({}, ReactRouter.Navigation, { query = this.context.router.getCurrentQuery(); } - // FIXME: react-router is just broken, - // we hopefully just need to wait for the next release with https://github.com/rackt/react-router/pull/957. this.context.router.replaceWith(routeNameOrPath, params, query); } }); -- cgit v1.2.3 From dcb42b3016415865848cdc2607ff640c1fd50818 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Fri, 27 Mar 2015 16:54:21 +0100 Subject: web: fix react-router --- web/src/js/components/common.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'web/src/js/components/common.js') diff --git a/web/src/js/components/common.js b/web/src/js/components/common.js index ba4c93c2..433e4f10 100644 --- a/web/src/js/components/common.js +++ b/web/src/js/components/common.js @@ -67,10 +67,12 @@ var Navigation = _.extend({}, ReactRouter.Navigation, { // we may remove this mixin and access react-router directly again. var State = _.extend({}, ReactRouter.State, { getQuery: function(){ - return this.context.router.getCurrentQuery(); + // For whatever reason, react-router always returns the same object, which makes comparing + // the current props with nextProps impossible. As a workaround, we just clone the query object. + return _.clone(this.context.router.getCurrentQuery()); }, getParams: function(){ - return this.context.router.getCurrentParams(); + return _.clone(this.context.router.getCurrentParams()); } }); -- cgit v1.2.3 From 1913975fa60c76bfb7e79a908b18e7e93793f71f Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Fri, 27 Mar 2015 21:58:04 +0100 Subject: web: use contexts to pass down stores. Using contexts frees us from the contracts we have using props - namely, we can assume them to be constant for the lifetime of the object. --- web/src/js/components/common.js | 55 +++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 16 deletions(-) (limited to 'web/src/js/components/common.js') diff --git a/web/src/js/components/common.js b/web/src/js/components/common.js index 433e4f10..b0aa0977 100644 --- a/web/src/js/components/common.js +++ b/web/src/js/components/common.js @@ -7,8 +7,8 @@ var AutoScrollMixin = { componentWillUpdate: function () { var node = this.getDOMNode(); this._shouldScrollBottom = ( - node.scrollTop !== 0 && - node.scrollTop + node.clientHeight === node.scrollHeight + node.scrollTop !== 0 && + node.scrollTop + node.clientHeight === node.scrollHeight ); }, componentDidUpdate: function () { @@ -29,32 +29,54 @@ var StickyHeadMixin = { } }; +var SettingsState = { + contextTypes: { + settingsStore: React.PropTypes.object.isRequired + }, + getInitialState: function () { + return { + settings: this.context.settingsStore.dict + }; + }, + componentDidMount: function () { + this.context.settingsStore.addListener("recalculate", this.onSettingsChange); + }, + componentWillUnmount: function () { + this.context.settingsStore.removeListener("recalculate", this.onSettingsChange); + }, + onSettingsChange: function () { + this.setState({ + settings: this.context.settingsStore.dict + }); + }, +}; + var ChildFocus = { - contextTypes: { - returnFocus: React.PropTypes.func - } + contextTypes: { + returnFocus: React.PropTypes.func + } }; var Navigation = _.extend({}, ReactRouter.Navigation, { setQuery: function (dict) { var q = this.context.router.getCurrentQuery(); - for(var i in dict){ - if(dict.hasOwnProperty(i)){ + for (var i in dict) { + if (dict.hasOwnProperty(i)) { q[i] = dict[i] || undefined; //falsey values shall be removed. } } this.replaceWith(this.context.router.getCurrentPath(), this.context.router.getCurrentParams(), q); }, - replaceWith: function(routeNameOrPath, params, query) { - if(routeNameOrPath === undefined){ + replaceWith: function (routeNameOrPath, params, query) { + if (routeNameOrPath === undefined) { routeNameOrPath = this.context.router.getCurrentPath(); } - if(params === undefined){ + if (params === undefined) { params = this.context.router.getCurrentParams(); } - if(query === undefined) { + if (query === undefined) { query = this.context.router.getCurrentQuery(); } @@ -65,13 +87,13 @@ var Navigation = _.extend({}, ReactRouter.Navigation, { // react-router is fairly good at changing its API regularly. // We keep the old method for now - if it should turn out that their changes are permanent, // we may remove this mixin and access react-router directly again. -var State = _.extend({}, ReactRouter.State, { - getQuery: function(){ +var RouterState = _.extend({}, ReactRouter.State, { + getQuery: function () { // For whatever reason, react-router always returns the same object, which makes comparing // the current props with nextProps impossible. As a workaround, we just clone the query object. return _.clone(this.context.router.getCurrentQuery()); }, - getParams: function(){ + getParams: function () { return _.clone(this.context.router.getCurrentParams()); } }); @@ -183,9 +205,10 @@ var Splitter = React.createClass({ module.exports = { ChildFocus: ChildFocus, - State: State, + RouterState: RouterState, Navigation: Navigation, StickyHeadMixin: StickyHeadMixin, AutoScrollMixin: AutoScrollMixin, - Splitter: Splitter + Splitter: Splitter, + SettingsState: SettingsState }; \ No newline at end of file -- cgit v1.2.3 From 3f5ca10c39a9f7d55e0f6943caf8f6ff762a0222 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Fri, 1 May 2015 17:24:44 +0200 Subject: mitmweb: add editor --- web/src/js/components/common.js | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'web/src/js/components/common.js') diff --git a/web/src/js/components/common.js b/web/src/js/components/common.js index b0aa0977..965ae9a7 100644 --- a/web/src/js/components/common.js +++ b/web/src/js/components/common.js @@ -55,6 +55,11 @@ var SettingsState = { var ChildFocus = { contextTypes: { returnFocus: React.PropTypes.func + }, + returnFocus: function(){ + React.findDOMNode(this).blur(); + window.getSelection().removeAllRanges(); + this.context.returnFocus(); } }; -- cgit v1.2.3