react-pushstate-anchor
Advanced tools
Comparing version 0.1.3 to 0.1.4
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -45,22 +47,53 @@ | ||
var PushStateAnchor = function PushStateAnchor(props) { | ||
return React.createElement( | ||
Consumer, | ||
null, | ||
function (value) { | ||
return React.createElement( | ||
'a', | ||
{ | ||
href: props.href, | ||
onClick: function onClick(event) { | ||
event.preventDefault(); | ||
value.history.push(props.href); | ||
} | ||
}, | ||
props.children | ||
); | ||
} | ||
); | ||
}; | ||
var PushStateAnchor = function (_Component2) { | ||
_inherits(PushStateAnchor, _Component2); | ||
function PushStateAnchor() { | ||
_classCallCheck(this, PushStateAnchor); | ||
var _this2 = _possibleConstructorReturn(this, _Component2.call(this)); | ||
_this2.state = { | ||
clientReady: false | ||
}; | ||
_this2.interceptOnClick = _this2.interceptOnClick.bind(_this2); | ||
return _this2; | ||
} | ||
PushStateAnchor.prototype.componentDidMount = function componentDidMount() { | ||
this.setState({ clientReady: true }); | ||
}; | ||
PushStateAnchor.prototype.interceptOnClick = function interceptOnClick(event, value) { | ||
event.preventDefault(); | ||
value.history.push(this.props.href); | ||
}; | ||
PushStateAnchor.prototype.render = function render() { | ||
var _this3 = this; | ||
var _props = this.props, | ||
_onClick = _props.onClick, | ||
otherProps = _objectWithoutProperties(_props, ['onClick']); | ||
return React.createElement( | ||
Consumer, | ||
null, | ||
function (value) { | ||
return React.createElement( | ||
'a', | ||
_extends({ | ||
onClick: function onClick(event) { | ||
_this3.state.clientReady ? _this3.interceptOnClick(event, value) : _onClick(event); | ||
} | ||
}, otherProps), | ||
otherProps.children | ||
); | ||
} | ||
); | ||
}; | ||
return PushStateAnchor; | ||
}(Component); | ||
var PushStateLocation = function PushStateLocation(props) { | ||
@@ -67,0 +100,0 @@ return React.createElement( |
71
index.js
@@ -18,2 +18,4 @@ 'use strict'; | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -58,22 +60,53 @@ | ||
var PushStateAnchor = function PushStateAnchor(props) { | ||
return _react2.default.createElement( | ||
Consumer, | ||
null, | ||
function (value) { | ||
return _react2.default.createElement( | ||
'a', | ||
{ | ||
href: props.href, | ||
onClick: function onClick(event) { | ||
event.preventDefault(); | ||
value.history.push(props.href); | ||
} | ||
}, | ||
props.children | ||
); | ||
} | ||
); | ||
}; | ||
var PushStateAnchor = function (_Component2) { | ||
_inherits(PushStateAnchor, _Component2); | ||
function PushStateAnchor() { | ||
_classCallCheck(this, PushStateAnchor); | ||
var _this2 = _possibleConstructorReturn(this, _Component2.call(this)); | ||
_this2.state = { | ||
clientReady: false | ||
}; | ||
_this2.interceptOnClick = _this2.interceptOnClick.bind(_this2); | ||
return _this2; | ||
} | ||
PushStateAnchor.prototype.componentDidMount = function componentDidMount() { | ||
this.setState({ clientReady: true }); | ||
}; | ||
PushStateAnchor.prototype.interceptOnClick = function interceptOnClick(event, value) { | ||
event.preventDefault(); | ||
value.history.push(this.props.href); | ||
}; | ||
PushStateAnchor.prototype.render = function render() { | ||
var _this3 = this; | ||
var _props = this.props, | ||
_onClick = _props.onClick, | ||
otherProps = _objectWithoutProperties(_props, ['onClick']); | ||
return _react2.default.createElement( | ||
Consumer, | ||
null, | ||
function (value) { | ||
return _react2.default.createElement( | ||
'a', | ||
_extends({ | ||
onClick: function onClick(event) { | ||
_this3.state.clientReady ? _this3.interceptOnClick(event, value) : _onClick(event); | ||
} | ||
}, otherProps), | ||
otherProps.children | ||
); | ||
} | ||
); | ||
}; | ||
return PushStateAnchor; | ||
}(_react.Component); | ||
var PushStateLocation = function PushStateLocation(props) { | ||
@@ -80,0 +113,0 @@ return _react2.default.createElement( |
{ | ||
"name": "react-pushstate-anchor", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"main": "index.js", | ||
"module": "es/index.js", | ||
"devDependencies": { | ||
"react-scripts": "1.1.4", | ||
"babel-cli": "^6.26.0", | ||
@@ -25,2 +24,3 @@ "babel-eslint": "^8.2.1", | ||
"raf": "^3.4.0", | ||
"react-scripts": "1.1.4", | ||
"rollup": "^0.50.1", | ||
@@ -39,5 +39,5 @@ "rollup-plugin-babel": "^3.0.3", | ||
"peerDependencies": { | ||
"react": ">=16.3.1", | ||
"react-dom": ">=16.3.1", | ||
"history": "^4.7.2" | ||
"history": "^4.7.2", | ||
"react": "^16.3.1", | ||
"react-dom": "^16.3.1" | ||
}, | ||
@@ -50,3 +50,4 @@ "scripts": { | ||
"prepublishOnly": "node ./tools/build.js" | ||
} | ||
}, | ||
"dependencies": {} | ||
} |
@@ -181,4 +181,14 @@ (function (global, factory) { | ||
var objectWithoutProperties = function (obj, keys) { | ||
var target = {}; | ||
for (var i in obj) { | ||
if (keys.indexOf(i) >= 0) continue; | ||
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; | ||
target[i] = obj[i]; | ||
} | ||
return target; | ||
}; | ||
var possibleConstructorReturn = function (self, call) { | ||
@@ -225,22 +235,53 @@ if (!self) { | ||
var PushStateAnchor = function PushStateAnchor(props) { | ||
return React__default.createElement( | ||
Consumer, | ||
null, | ||
function (value) { | ||
return React__default.createElement( | ||
'a', | ||
{ | ||
href: props.href, | ||
onClick: function onClick(event) { | ||
event.preventDefault(); | ||
value.history.push(props.href); | ||
} | ||
}, | ||
props.children | ||
); | ||
} | ||
); | ||
}; | ||
var PushStateAnchor = function (_Component2) { | ||
inherits(PushStateAnchor, _Component2); | ||
function PushStateAnchor() { | ||
classCallCheck(this, PushStateAnchor); | ||
var _this2 = possibleConstructorReturn(this, _Component2.call(this)); | ||
_this2.state = { | ||
clientReady: false | ||
}; | ||
_this2.interceptOnClick = _this2.interceptOnClick.bind(_this2); | ||
return _this2; | ||
} | ||
PushStateAnchor.prototype.componentDidMount = function componentDidMount() { | ||
this.setState({ clientReady: true }); | ||
}; | ||
PushStateAnchor.prototype.interceptOnClick = function interceptOnClick(event, value) { | ||
event.preventDefault(); | ||
value.history.push(this.props.href); | ||
}; | ||
PushStateAnchor.prototype.render = function render() { | ||
var _this3 = this; | ||
var _props = this.props, | ||
_onClick = _props.onClick, | ||
otherProps = objectWithoutProperties(_props, ['onClick']); | ||
return React__default.createElement( | ||
Consumer, | ||
null, | ||
function (value) { | ||
return React__default.createElement( | ||
'a', | ||
_extends({ | ||
onClick: function onClick(event) { | ||
_this3.state.clientReady ? _this3.interceptOnClick(event, value) : _onClick(event); | ||
} | ||
}, otherProps), | ||
otherProps.children | ||
); | ||
} | ||
); | ||
}; | ||
return PushStateAnchor; | ||
}(React.Component); | ||
var PushStateLocation = function PushStateLocation(props) { | ||
@@ -247,0 +288,0 @@ return React__default.createElement( |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("history/createBrowserHistory")):"function"==typeof define&&define.amd?define(["exports","react","history/createBrowserHistory"],e):e(t.ReactPushStateAnchor={},t.React,t.createHistory)}(this,function(t,e,n){"use strict";var r="default"in e?e.default:e;n=n&&n.hasOwnProperty("default")?n.default:n;!function(){function t(t){this.value=t}function e(e){var n,r;function o(n,r){try{var u=e[n](r),c=u.value;c instanceof t?Promise.resolve(c.value).then(function(t){o("next",t)},function(t){o("throw",t)}):i(u.done?"return":"normal",u.value)}catch(t){i("throw",t)}}function i(t,e){switch(t){case"return":n.resolve({value:e,done:!0});break;case"throw":n.reject(e);break;default:n.resolve({value:e,done:!1})}(n=n.next)?o(n.key,n.arg):r=null}this._invoke=function(t,e){return new Promise(function(i,u){var c={key:t,arg:e,resolve:i,reject:u,next:null};r?r=r.next=c:(n=r=c,o(t,e))})},"function"!=typeof e.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(t){return this._invoke("next",t)},e.prototype.throw=function(t){return this._invoke("throw",t)},e.prototype.return=function(t){return this._invoke("return",t)}}();var o=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},i=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},u=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},c=r.createContext("push-state-anchor"),a=c.Provider,s=c.Consumer,f=function(t){function e(){o(this,e);var r=u(this,t.call(this));return r.state={location:window.location},r.history=n(),r.history.listen(function(t){return r.setState({location:t})}),r}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,t),e.prototype.render=function(){return r.createElement(a,{value:i({history:this.history},this.state)},this.props.children)},e}(e.Component);t.PushStateAnchorProvider=f,t.PushStateAnchor=function(t){return r.createElement(s,null,function(e){return r.createElement("a",{href:t.href,onClick:function(n){n.preventDefault(),e.history.push(t.href)}},t.children)})},t.PushStateLocation=function(t){return r.createElement(s,null,function(e){return t.children(e.location)})},Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("history/createBrowserHistory")):"function"==typeof define&&define.amd?define(["exports","react","history/createBrowserHistory"],e):e(t.ReactPushStateAnchor={},t.React,t.createHistory)}(this,function(t,e,n){"use strict";var r="default"in e?e.default:e;n=n&&n.hasOwnProperty("default")?n.default:n;!function(){function t(t){this.value=t}function e(e){var n,r;function o(n,r){try{var c=e[n](r),u=c.value;u instanceof t?Promise.resolve(u.value).then(function(t){o("next",t)},function(t){o("throw",t)}):i(c.done?"return":"normal",c.value)}catch(t){i("throw",t)}}function i(t,e){switch(t){case"return":n.resolve({value:e,done:!0});break;case"throw":n.reject(e);break;default:n.resolve({value:e,done:!1})}(n=n.next)?o(n.key,n.arg):r=null}this._invoke=function(t,e){return new Promise(function(i,c){var u={key:t,arg:e,resolve:i,reject:c,next:null};r?r=r.next=u:(n=r=u,o(t,e))})},"function"!=typeof e.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(t){return this._invoke("next",t)},e.prototype.throw=function(t){return this._invoke("throw",t)},e.prototype.return=function(t){return this._invoke("return",t)}}();var o=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},i=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},c=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},u=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},a=r.createContext("push-state-anchor"),s=a.Provider,l=a.Consumer,f=function(t){function e(){o(this,e);var r=u(this,t.call(this));return r.state={location:window.location},r.history=n(),r.history.listen(function(t){return r.setState({location:t})}),r}return c(e,t),e.prototype.render=function(){return r.createElement(s,{value:i({history:this.history},this.state)},this.props.children)},e}(e.Component),p=function(t){function e(){o(this,e);var n=u(this,t.call(this));return n.state={clientReady:!1},n.interceptOnClick=n.interceptOnClick.bind(n),n}return c(e,t),e.prototype.componentDidMount=function(){this.setState({clientReady:!0})},e.prototype.interceptOnClick=function(t,e){t.preventDefault(),e.history.push(this.props.href)},e.prototype.render=function(){var t=this,e=this.props,n=e.onClick,o=function(t,e){var n={};for(var r in t)e.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r]);return n}(e,["onClick"]);return r.createElement(l,null,function(e){return r.createElement("a",i({onClick:function(r){t.state.clientReady?t.interceptOnClick(r,e):n(r)}},o),o.children)})},e}(e.Component);t.PushStateAnchorProvider=f,t.PushStateAnchor=p,t.PushStateLocation=function(t){return r.createElement(l,null,function(e){return t.children(e.location)})},Object.defineProperty(t,"__esModule",{value:!0})}); |
22643
417