boring-router-react
Advanced tools
Comparing version 0.3.0-alpha.45 to 0.3.0-alpha.46
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.composeEventHandler = exports.then = void 0; | ||
const FULFILLED_PROMISE = Promise.resolve(); | ||
@@ -4,0 +5,0 @@ function then(handler) { |
@@ -26,4 +26,4 @@ import { AbstractHistory, HistorySnapshot } from 'boring-router'; | ||
constructor({ prefix, hash }?: BrowserHistoryOptions); | ||
readonly url: string; | ||
private readonly hashPrefix; | ||
get url(): string; | ||
private get hashPrefix(); | ||
getHRefByRef(ref: string): string; | ||
@@ -30,0 +30,0 @@ getRefByHRef(href: string): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BrowserHistory = void 0; | ||
const boring_router_1 = require("boring-router"); | ||
@@ -4,0 +5,0 @@ class BrowserHistory extends boring_router_1.AbstractHistory { |
@@ -13,5 +13,5 @@ import { RouteBuilder, RouteMatch, RouteMatchSharedToParamDict } from 'boring-router'; | ||
export declare class Link<T extends RouteMatch | RouteBuilder> extends Component<LinkProps<T>> { | ||
private readonly href; | ||
private get href(); | ||
render(): ReactNode; | ||
private onClick; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Link = void 0; | ||
const tslib_1 = require("tslib"); | ||
@@ -9,58 +10,61 @@ const boring_router_1 = require("boring-router"); | ||
const _utils_1 = require("./@utils"); | ||
let Link = class Link extends react_1.Component { | ||
constructor() { | ||
super(...arguments); | ||
this.onClick = (event) => { | ||
if (event.ctrlKey || | ||
event.metaKey || | ||
event.button === 1 /* middle button */) { | ||
return; | ||
} | ||
event.preventDefault(); | ||
let { to, params, replace, toggle = false, leave } = this.props; | ||
if (to instanceof boring_router_1.RouteMatch) { | ||
let leaveOption = leave === undefined ? toggle && to.$matched : leave; | ||
if (replace) { | ||
to.$replace(params, { leave: leaveOption }); | ||
let Link = /** @class */ (() => { | ||
let Link = class Link extends react_1.Component { | ||
constructor() { | ||
super(...arguments); | ||
this.onClick = (event) => { | ||
if (event.ctrlKey || | ||
event.metaKey || | ||
event.button === 1 /* middle button */) { | ||
return; | ||
} | ||
event.preventDefault(); | ||
let { to, params, replace, toggle = false, leave } = this.props; | ||
if (to instanceof boring_router_1.RouteMatch) { | ||
let leaveOption = leave === undefined ? toggle && to.$matched : leave; | ||
if (replace) { | ||
to.$replace(params, { leave: leaveOption }); | ||
} | ||
else { | ||
to.$push(params, { leave: leaveOption }); | ||
} | ||
} | ||
else { | ||
to.$push(params, { leave: leaveOption }); | ||
if (replace) { | ||
to.$replace(); | ||
} | ||
else { | ||
to.$push(); | ||
} | ||
} | ||
} | ||
else { | ||
if (replace) { | ||
to.$replace(); | ||
}; | ||
} | ||
get href() { | ||
let { to, params } = this.props; | ||
try { | ||
if (to instanceof boring_router_1.RouteMatch) { | ||
return to.$href(params); | ||
} | ||
else { | ||
to.$push(); | ||
return to.$href(); | ||
} | ||
} | ||
}; | ||
} | ||
get href() { | ||
let { to, params } = this.props; | ||
try { | ||
if (to instanceof boring_router_1.RouteMatch) { | ||
return to.$href(params); | ||
catch (error) { | ||
return '#'; | ||
} | ||
else { | ||
return to.$href(); | ||
} | ||
} | ||
catch (error) { | ||
return '#'; | ||
render() { | ||
let { className, to, params, replace, toggle, onClick, ...props } = this.props; | ||
return (react_1.default.createElement("a", Object.assign({ className: className, href: this.href, onClick: _utils_1.composeEventHandler([onClick, this.onClick], true) }, props))); | ||
} | ||
} | ||
render() { | ||
let { className, to, params, replace, toggle, onClick, ...props } = this.props; | ||
return (react_1.default.createElement("a", Object.assign({ className: className, href: this.href, onClick: _utils_1.composeEventHandler([onClick, this.onClick], true) }, props))); | ||
} | ||
}; | ||
tslib_1.__decorate([ | ||
mobx_1.computed | ||
], Link.prototype, "href", null); | ||
Link = tslib_1.__decorate([ | ||
mobx_react_1.observer | ||
], Link); | ||
}; | ||
tslib_1.__decorate([ | ||
mobx_1.computed | ||
], Link.prototype, "href", null); | ||
Link = tslib_1.__decorate([ | ||
mobx_react_1.observer | ||
], Link); | ||
return Link; | ||
})(); | ||
exports.Link = Link; | ||
//# sourceMappingURL=link.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.NavLink = void 0; | ||
const tslib_1 = require("tslib"); | ||
@@ -8,14 +9,17 @@ const classnames_1 = tslib_1.__importDefault(require("classnames")); | ||
const link_1 = require("./link"); | ||
let NavLink = class NavLink extends react_1.Component { | ||
render() { | ||
let { className, activeClassName = 'active', exact, ...props } = this.props; | ||
let { to } = props; | ||
let matched = exact ? to.$exact : to.$matched; | ||
return (react_1.default.createElement(link_1.Link, Object.assign({ className: classnames_1.default(className, matched && activeClassName) }, props))); | ||
} | ||
}; | ||
NavLink = tslib_1.__decorate([ | ||
mobx_react_1.observer | ||
], NavLink); | ||
let NavLink = /** @class */ (() => { | ||
let NavLink = class NavLink extends react_1.Component { | ||
render() { | ||
let { className, activeClassName = 'active', exact, ...props } = this.props; | ||
let { to } = props; | ||
let matched = exact ? to.$exact : to.$matched; | ||
return (react_1.default.createElement(link_1.Link, Object.assign({ className: classnames_1.default(className, matched && activeClassName) }, props))); | ||
} | ||
}; | ||
NavLink = tslib_1.__decorate([ | ||
mobx_react_1.observer | ||
], NavLink); | ||
return NavLink; | ||
})(); | ||
exports.NavLink = NavLink; | ||
//# sourceMappingURL=nav-link.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Redirect = void 0; | ||
const tslib_1 = require("tslib"); | ||
@@ -7,32 +8,35 @@ const mobx_react_1 = require("mobx-react"); | ||
const _utils_1 = require("./@utils"); | ||
let Redirect = class Redirect extends react_1.Component { | ||
render() { | ||
let { match, exact } = this.props; | ||
let matched; | ||
if (typeof match === 'boolean') { | ||
matched = match; | ||
let Redirect = /** @class */ (() => { | ||
let Redirect = class Redirect extends react_1.Component { | ||
render() { | ||
let { match, exact } = this.props; | ||
let matched; | ||
if (typeof match === 'boolean') { | ||
matched = match; | ||
} | ||
else { | ||
let matches = Array.isArray(match) ? match : [match]; | ||
matched = matches.some(match => (exact ? match.$exact : match.$matched)); | ||
} | ||
if (matched) { | ||
_utils_1.then(() => this.redirect()); | ||
} | ||
return react_1.default.createElement(react_1.default.Fragment, null); | ||
} | ||
else { | ||
let matches = Array.isArray(match) ? match : [match]; | ||
matched = matches.some(match => (exact ? match.$exact : match.$matched)); | ||
redirect() { | ||
let { to, params, push } = this.props; | ||
if (push) { | ||
to.$push(params); | ||
} | ||
else { | ||
to.$replace(params); | ||
} | ||
} | ||
if (matched) { | ||
_utils_1.then(() => this.redirect()); | ||
} | ||
return react_1.default.createElement(react_1.default.Fragment, null); | ||
} | ||
redirect() { | ||
let { to, params, push } = this.props; | ||
if (push) { | ||
to.$push(params); | ||
} | ||
else { | ||
to.$replace(params); | ||
} | ||
} | ||
}; | ||
Redirect = tslib_1.__decorate([ | ||
mobx_react_1.observer | ||
], Redirect); | ||
}; | ||
Redirect = tslib_1.__decorate([ | ||
mobx_react_1.observer | ||
], Redirect); | ||
return Redirect; | ||
})(); | ||
exports.Redirect = Redirect; | ||
//# sourceMappingURL=redirect.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Route = void 0; | ||
const tslib_1 = require("tslib"); | ||
const mobx_react_1 = require("mobx-react"); | ||
const react_1 = tslib_1.__importStar(require("react")); | ||
let Route = class Route extends react_1.Component { | ||
render() { | ||
let { match, exact, component: RouteComponent, children } = this.props; | ||
let matches = Array.isArray(match) ? match : [match]; | ||
let firstMatch = matches.find(match => exact ? match.$exact : match.$matched); | ||
if (firstMatch) { | ||
if (children !== undefined && children !== null) { | ||
if (RouteComponent) { | ||
throw new Error('Cannot specify `component` and `children` simultaneously'); | ||
let Route = /** @class */ (() => { | ||
let Route = class Route extends react_1.Component { | ||
render() { | ||
let { match, exact, component: RouteComponent, children } = this.props; | ||
let matches = Array.isArray(match) ? match : [match]; | ||
let firstMatch = matches.find(match => exact ? match.$exact : match.$matched); | ||
if (firstMatch) { | ||
if (children !== undefined && children !== null) { | ||
if (RouteComponent) { | ||
throw new Error('Cannot specify `component` and `children` simultaneously'); | ||
} | ||
if (typeof children === 'function') { | ||
return children(firstMatch); | ||
} | ||
else { | ||
return children; | ||
} | ||
} | ||
if (typeof children === 'function') { | ||
return children(firstMatch); | ||
} | ||
else { | ||
return children; | ||
if (RouteComponent) { | ||
return react_1.default.createElement(RouteComponent, { match: firstMatch }); | ||
} | ||
} | ||
} | ||
else { | ||
if (RouteComponent) { | ||
return react_1.default.createElement(RouteComponent, { match: firstMatch }); | ||
} | ||
} | ||
return react_1.default.createElement(react_1.default.Fragment, null); | ||
} | ||
return react_1.default.createElement(react_1.default.Fragment, null); | ||
} | ||
}; | ||
Route = tslib_1.__decorate([ | ||
mobx_react_1.observer | ||
], Route); | ||
}; | ||
Route = tslib_1.__decorate([ | ||
mobx_react_1.observer | ||
], Route); | ||
return Route; | ||
})(); | ||
exports.Route = Route; | ||
//# sourceMappingURL=route.js.map |
{ | ||
"name": "boring-router-react", | ||
"version": "0.3.0-alpha.45", | ||
"version": "0.3.0-alpha.46", | ||
"description": "A light-weight, type-safe, yet reactive router service using MobX.", | ||
@@ -42,3 +42,3 @@ "repository": { | ||
}, | ||
"gitHead": "38d6c5edb95fcddbd7d5713a8419a3bd3da2a856" | ||
"gitHead": "af5f8836b8cd7ff0e777a00c9f93eb229ab20912" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48245
948