🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@uirouter/dsr

Package Overview
Dependencies
Maintainers
4
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uirouter/dsr - npm Package Compare versions

Comparing version

to
1.0.3

CHANGELOG.md

259

_bundles/ui-router-dsr.js
/**
* UI-Router Deep State Redirect: redirect to the most recently activated child state
* @version v1.0.2
* @version v1.0.3
* @link https://ui-router.github.io

@@ -8,127 +8,162 @@ * @license MIT License, http://www.opensource.org/licenses/MIT

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@uirouter/core')) :
typeof define === 'function' && define.amd ? define(['exports', '@uirouter/core'], factory) :
(factory((global['@uirouter/dsr'] = global['@uirouter/dsr'] || {}),global['@uirouter/core']));
}(this, (function (exports,_uirouter_core) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@uirouter/core')) :
typeof define === 'function' && define.amd ? define(['exports', '@uirouter/core'], factory) :
(factory((global['@uirouter/dsr'] = {}),global['@uirouter/core']));
}(this, (function (exports,core) { 'use strict';
function DSRPlugin($uiRouter) {
var $transitions = $uiRouter.transitionService;
var $state = $uiRouter.stateService;
$transitions.onRetain({ retained: getDsr }, recordDeepState);
$transitions.onEnter({ entering: getDsr }, recordDeepState);
$transitions.onBefore({ to: getDsr }, deepStateRedirect);
function getDsr(state) {
return state.deepStateRedirect || state.dsr;
}
function getConfig(state) {
var dsrProp = getDsr(state);
var propType = typeof dsrProp;
if (propType === 'undefined')
return;
var params;
var defaultTarget = propType === 'string' ? dsrProp : undefined;
var fn = propType === 'function' ? dsrProp : undefined;
if (propType === 'object') {
fn = dsrProp.fn;
var defaultType = typeof dsrProp.default;
if (defaultType === 'object') {
defaultTarget = $state.target(dsrProp.default.state, dsrProp.default.params, dsrProp.default.options);
var DSRPlugin = /** @class */ (function () {
function DSRPlugin($uiRouter) {
var _this = this;
this.name = 'deep-state-redirect';
this.hookDeregFns = [];
this.$transitions = $uiRouter.transitionService;
this.$state = $uiRouter.stateService;
this.hookDeregFns.push(this.$transitions.onRetain({ retained: function (state) { return !!_this.getDsrProp(state.self); } }, this.recordDeepState.bind(this)));
this.hookDeregFns.push(this.$transitions.onEnter({ entering: function (state) { return !!_this.getDsrProp(state.self); } }, this.recordDeepState.bind(this)));
this.hookDeregFns.push(this.$transitions.onBefore({ to: function (state) { return !!_this.getDsrProp(state.self); } }, this.deepStateRedirect.bind(this)));
}
DSRPlugin.prototype.dispose = function (router) {
this.hookDeregFns.forEach(function (fn) { return fn(); });
};
/**
* Resets deep state redirect
*
* A deep state is recorded for each DSR state.
* This function resets recorded deep state redirect(s) to the initial value.
*
* If called with no parameters, the redirects for all states are reset.
*
* If called with a `state` parameter, the redirect for that state is reset.
*
* If called with `state` and `params` parameters, the redirect for that state and set of parameter values is reset.
*
* @param state (optional) the redirect for this state will be reset
* @param params (optional) the redirect for the state and parameters will be reset
*/
DSRPlugin.prototype.reset = function (state, params) {
var $state = this.$state;
if (!state) {
$state.get().forEach(function (_state) { return delete _state.$$state().$dsr; });
}
else if (defaultType === 'string') {
defaultTarget = $state.target(dsrProp.default);
else if (!params) {
delete $state.get(state).$$state().$dsr;
}
if (dsrProp.params === true) {
params = function () {
return true;
};
else {
var $$state = $state.get(state).$$state();
$$state.$dsr = $$state.$dsr.filter(this.paramsEqual($$state, params, undefined, true));
}
else if (Array.isArray(dsrProp.params)) {
params = function (param) {
return dsrProp.params.indexOf(param.id) !== -1;
};
};
/**
* Returns the recorded redirect
*
* Returns the recorded redirect for a given DSR `state` (and optionally `params`).
*
* @param state the DSR state
* @param params (optional) the parameter values
*
* @returns the recorded redirect `TargetState`
*/
DSRPlugin.prototype.getRedirect = function (state, params) {
return this.getDeepStateRedirect(state, params);
};
DSRPlugin.prototype.getDsrProp = function (state) {
return state.deepStateRedirect || state.dsr;
};
DSRPlugin.prototype.getConfig = function (state) {
var $state = this.$state;
var dsrProp = this.getDsrProp(state);
if (typeof dsrProp === 'undefined')
return;
var params;
var defaultTarget = typeof dsrProp === 'string' ? $state.target(dsrProp) : undefined;
var fn = typeof dsrProp === 'function' ? dsrProp : undefined;
if (typeof dsrProp === 'object') {
fn = dsrProp.fn;
if (typeof dsrProp.default === 'object') {
defaultTarget = $state.target(dsrProp.default.state, dsrProp.default.params, dsrProp.default.options);
}
else if (typeof dsrProp.default === 'string') {
defaultTarget = $state.target(dsrProp.default);
}
var paramsProp_1 = dsrProp.params;
if (paramsProp_1 === true) {
params = function () { return true; };
}
else if (Array.isArray(paramsProp_1)) {
params = function (param) { return paramsProp_1.indexOf(param.id) !== -1; };
}
}
}
fn = fn || (function (transition, target) { return target; });
return { params: params, default: defaultTarget, fn: fn };
}
function paramsEqual(state, transParams, schemaMatchFn, negate) {
if (negate === void 0) { negate = false; }
schemaMatchFn = schemaMatchFn || (function () { return true; });
var schema = state.parameters({ inherit: true }).filter(schemaMatchFn);
return function (redirect) {
var equals = _uirouter_core.Param.equals(schema, redirect.triggerParams, transParams);
return negate ? !equals : equals;
fn = fn || (function (transition, target) { return target; });
return { default: defaultTarget, params: params, fn: fn };
};
}
function recordDeepState(transition, state) {
var paramsConfig = getConfig(state).params;
transition.promise.then(function () {
var transTo = transition.to();
var transParams = transition.params();
var recordedDsrTarget = $state.target(transTo, transParams);
if (paramsConfig) {
state.$dsr = (state.$dsr || []).filter(paramsEqual(transTo.$$state(), transParams, undefined, true));
state.$dsr.push({ triggerParams: transParams, target: recordedDsrTarget });
DSRPlugin.prototype.paramsEqual = function (state, transParams, paramPredicate, negate) {
if (paramPredicate === void 0) { paramPredicate = function () { return true; }; }
if (negate === void 0) { negate = false; }
var schema = state.parameters({ inherit: true }).filter(paramPredicate);
return function (redirect) {
var equals = core.Param.equals(schema, redirect.triggerParams, transParams);
return negate ? !equals : equals;
};
};
DSRPlugin.prototype.recordDeepState = function (transition, state) {
var _this = this;
var $state = this.$state;
var paramsConfig = this.getConfig(state).params;
var _state = state.$$state();
transition.promise.then(function () {
var transTo = transition.to();
var transParams = transition.params();
var recordedDsrTarget = $state.target(transTo, transParams);
if (paramsConfig) {
var recordedDSR = _state.$dsr || [];
var predicate = _this.paramsEqual(transTo.$$state(), transParams, undefined, true);
_state.$dsr = recordedDSR.filter(predicate);
_state.$dsr.push({ triggerParams: transParams, target: recordedDsrTarget });
}
else {
_state.$dsr = recordedDsrTarget;
}
});
};
DSRPlugin.prototype.deepStateRedirect = function (transition) {
var opts = transition.options();
if (opts['ignoreDsr'] || (opts.custom && opts.custom.ignoreDsr))
return;
var config = this.getConfig(transition.to());
var redirect = this.getDeepStateRedirect(transition.to(), transition.params());
redirect = config.fn(transition, redirect);
if (redirect && redirect.state() === transition.to())
return;
return redirect;
};
DSRPlugin.prototype.getDeepStateRedirect = function (stateOrName, params) {
var $state = this.$state;
var _state = $state.get(stateOrName);
var state = _state && _state.$$state();
var config = this.getConfig(_state);
var dsrTarget;
if (config.params) {
var predicate = this.paramsEqual(state, params, config.params, false);
var match = state.$dsr && state.$dsr.filter(predicate)[0];
dsrTarget = match && match.target;
}
else {
state.$dsr = recordedDsrTarget;
dsrTarget = state.$dsr;
}
});
}
function deepStateRedirect(transition) {
var opts = transition.options();
if (opts['ignoreDsr'] || (opts.custom && opts.custom.ignoreDsr))
return;
var config = getConfig(transition.to());
var redirect = getDeepStateRedirect(transition.to(), transition.params());
redirect = config.fn(transition, redirect);
if (redirect && redirect.state() === transition.to())
return;
return redirect;
}
function getDeepStateRedirect(stateOrName, params) {
var state = $state.get(stateOrName);
var dsrTarget, config = getConfig(state);
var $$state = state.$$state();
if (config.params) {
var predicate = paramsEqual($$state, params, config.params, false);
var match = $$state['$dsr'] && $$state['$dsr'].filter(predicate)[0];
dsrTarget = match && match.target;
}
else {
dsrTarget = $$state['$dsr'];
}
dsrTarget = dsrTarget || config.default;
if (dsrTarget) {
// merge original params with deep state redirect params
var targetParams = Object.assign({}, params, dsrTarget.params());
dsrTarget = $state.target(dsrTarget.state(), targetParams, dsrTarget.options());
}
return dsrTarget;
}
return {
name: 'deep-state-redirect',
reset: function (state, params) {
if (!state) {
$state.get().forEach(function (state) { return delete state.$$state()['$dsr']; });
dsrTarget = dsrTarget || config.default;
if (dsrTarget) {
// merge original params with deep state redirect params
var targetParams = Object.assign({}, params, dsrTarget.params());
dsrTarget = $state.target(dsrTarget.state(), targetParams, dsrTarget.options());
}
else if (!params) {
delete $state.get(state).$$state()['$dsr'];
}
else {
var $$state = $state.get(state).$$state();
$$state['$dsr'] = $$state['$dsr'].filter(paramsEqual($$state, params, null, true));
}
},
getRedirect: function (state, params) {
return getDeepStateRedirect(state, params);
},
};
}
return dsrTarget;
};
return DSRPlugin;
}());
exports.DSRPlugin = DSRPlugin;
exports.DSRPlugin = DSRPlugin;
Object.defineProperty(exports, '__esModule', { value: true });
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=ui-router-dsr.js.map
/**
* UI-Router Deep State Redirect: redirect to the most recently activated child state
* @version v1.0.2
* @version v1.0.3
* @link https://ui-router.github.io
* @license MIT License, http://www.opensource.org/licenses/MIT
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@uirouter/core")):"function"==typeof define&&define.amd?define(["exports","@uirouter/core"],t):t(e["@uirouter/dsr"]=e["@uirouter/dsr"]||{},e["@uirouter/core"])}(this,function(e,t){"use strict";function r(e){function r(e){return e.deepStateRedirect||e.dsr}function n(e){var t=r(e),n=typeof t;if("undefined"!==n){var a,i="string"===n?t:void 0,o="function"===n?t:void 0;if("object"===n){o=t.fn;var s=typeof t.default;"object"===s?i=f.target(t.default.state,t.default.params,t.default.options):"string"===s&&(i=f.target(t.default)),!0===t.params?a=function(){return!0}:Array.isArray(t.params)&&(a=function(e){return-1!==t.params.indexOf(e.id)})}return o=o||function(e,t){return t},{params:a,default:i,fn:o}}}function a(e,r,n,a){void 0===a&&(a=!1),n=n||function(){return!0};var i=e.parameters({inherit:!0}).filter(n);return function(e){var n=t.Param.equals(i,e.triggerParams,r);return a?!n:n}}function i(e,t){var r=n(t).params;e.promise.then(function(){var n=e.to(),i=e.params(),o=f.target(n,i);r?(t.$dsr=(t.$dsr||[]).filter(a(n.$$state(),i,void 0,!0)),t.$dsr.push({triggerParams:i,target:o})):t.$dsr=o})}function o(e){var t=e.options();if(!(t.ignoreDsr||t.custom&&t.custom.ignoreDsr)){var r=n(e.to()),a=s(e.to(),e.params());if(!(a=r.fn(e,a))||a.state()!==e.to())return a}}function s(e,t){var r,i=f.get(e),o=n(i),s=i.$$state();if(o.params){var u=a(s,t,o.params,!1),d=s.$dsr&&s.$dsr.filter(u)[0];r=d&&d.target}else r=s.$dsr;if(r=r||o.default){var c=Object.assign({},t,r.params());r=f.target(r.state(),c,r.options())}return r}var u=e.transitionService,f=e.stateService;return u.onRetain({retained:r},i),u.onEnter({entering:r},i),u.onBefore({to:r},o),{name:"deep-state-redirect",reset:function(e,t){if(e)if(t){var r=f.get(e).$$state();r.$dsr=r.$dsr.filter(a(r,t,null,!0))}else delete f.get(e).$$state().$dsr;else f.get().forEach(function(e){return delete e.$$state().$dsr})},getRedirect:function(e,t){return s(e,t)}}}e.DSRPlugin=r,Object.defineProperty(e,"__esModule",{value:!0})});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@uirouter/core")):"function"==typeof define&&define.amd?define(["exports","@uirouter/core"],e):e(t["@uirouter/dsr"]={},t["@uirouter/core"])}(this,function(t,e){"use strict";var r=function(){function t(t){var e=this;this.name="deep-state-redirect",this.hookDeregFns=[],this.$transitions=t.transitionService,this.$state=t.stateService,this.hookDeregFns.push(this.$transitions.onRetain({retained:function(t){return!!e.getDsrProp(t.self)}},this.recordDeepState.bind(this))),this.hookDeregFns.push(this.$transitions.onEnter({entering:function(t){return!!e.getDsrProp(t.self)}},this.recordDeepState.bind(this))),this.hookDeregFns.push(this.$transitions.onBefore({to:function(t){return!!e.getDsrProp(t.self)}},this.deepStateRedirect.bind(this)))}return t.prototype.dispose=function(t){this.hookDeregFns.forEach(function(t){return t()})},t.prototype.reset=function(t,e){var r=this.$state;if(t)if(e){var i=r.get(t).$$state();i.$dsr=i.$dsr.filter(this.paramsEqual(i,e,void 0,!0))}else delete r.get(t).$$state().$dsr;else r.get().forEach(function(t){return delete t.$$state().$dsr})},t.prototype.getRedirect=function(t,e){return this.getDeepStateRedirect(t,e)},t.prototype.getDsrProp=function(t){return t.deepStateRedirect||t.dsr},t.prototype.getConfig=function(t){var e=this.$state,r=this.getDsrProp(t);if(void 0!==r){var i,s="string"==typeof r?e.target(r):void 0,o="function"==typeof r?r:void 0;if("object"==typeof r){o=r.fn,"object"==typeof r.default?s=e.target(r.default.state,r.default.params,r.default.options):"string"==typeof r.default&&(s=e.target(r.default));var n=r.params;!0===n?i=function(){return!0}:Array.isArray(n)&&(i=function(t){return-1!==n.indexOf(t.id)})}return{default:s,params:i,fn:o=o||function(t,e){return e}}}},t.prototype.paramsEqual=function(t,r,i,s){void 0===i&&(i=function(){return!0}),void 0===s&&(s=!1);var o=t.parameters({inherit:!0}).filter(i);return function(t){var i=e.Param.equals(o,t.triggerParams,r);return s?!i:i}},t.prototype.recordDeepState=function(t,e){var r=this,i=this.$state,s=this.getConfig(e).params,o=e.$$state();t.promise.then(function(){var e=t.to(),n=t.params(),a=i.target(e,n);if(s){var u=o.$dsr||[],f=r.paramsEqual(e.$$state(),n,void 0,!0);o.$dsr=u.filter(f),o.$dsr.push({triggerParams:n,target:a})}else o.$dsr=a})},t.prototype.deepStateRedirect=function(t){var e=t.options();if(!(e.ignoreDsr||e.custom&&e.custom.ignoreDsr)){var r=this.getConfig(t.to()),i=this.getDeepStateRedirect(t.to(),t.params());if(!(i=r.fn(t,i))||i.state()!==t.to())return i}},t.prototype.getDeepStateRedirect=function(t,e){var r,i=this.$state,s=i.get(t),o=s&&s.$$state(),n=this.getConfig(s);if(n.params){var a=this.paramsEqual(o,e,n.params,!1),u=o.$dsr&&o.$dsr.filter(a)[0];r=u&&u.target}else r=o.$dsr;if(r=r||n.default){var f=Object.assign({},e,r.params());r=i.target(r.state(),f,r.options())}return r},t}();t.DSRPlugin=r,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=ui-router-dsr.min.js.map

@@ -1,9 +0,43 @@

import { UIRouter } from "@uirouter/core";
declare module "@uirouter/core" {
interface StateDeclaration {
dsr?: any;
deepStateRedirect?: any;
}
import { UIRouter, RawParams, StateOrName, TargetState, UIRouterPlugin, TransitionService, StateService } from '@uirouter/core';
declare class DSRPlugin implements UIRouterPlugin {
name: string;
$transitions: TransitionService;
$state: StateService;
hookDeregFns: any[];
constructor($uiRouter: UIRouter);
dispose(router: UIRouter): void;
/**
* Resets deep state redirect
*
* A deep state is recorded for each DSR state.
* This function resets recorded deep state redirect(s) to the initial value.
*
* If called with no parameters, the redirects for all states are reset.
*
* If called with a `state` parameter, the redirect for that state is reset.
*
* If called with `state` and `params` parameters, the redirect for that state and set of parameter values is reset.
*
* @param state (optional) the redirect for this state will be reset
* @param params (optional) the redirect for the state and parameters will be reset
*/
reset(state?: StateOrName, params?: RawParams): void;
/**
* Returns the recorded redirect
*
* Returns the recorded redirect for a given DSR `state` (and optionally `params`).
*
* @param state the DSR state
* @param params (optional) the parameter values
*
* @returns the recorded redirect `TargetState`
*/
getRedirect(state: StateOrName, params?: RawParams): TargetState;
private getDsrProp(state);
private getConfig(state);
private paramsEqual(state, transParams, paramPredicate?, negate?);
private recordDeepState(transition, state);
private deepStateRedirect(transition);
private getDeepStateRedirect(stateOrName, params);
}
declare function DSRPlugin($uiRouter: UIRouter): any;
export { DSRPlugin };

@@ -1,46 +0,91 @@

import { Param } from "@uirouter/core";
function DSRPlugin($uiRouter) {
var $transitions = $uiRouter.transitionService;
var $state = $uiRouter.stateService;
$transitions.onRetain({ retained: getDsr }, recordDeepState);
$transitions.onEnter({ entering: getDsr }, recordDeepState);
$transitions.onBefore({ to: getDsr }, deepStateRedirect);
function getDsr(state) {
import { Param, } from '@uirouter/core';
var DSRPlugin = /** @class */ (function () {
function DSRPlugin($uiRouter) {
var _this = this;
this.name = 'deep-state-redirect';
this.hookDeregFns = [];
this.$transitions = $uiRouter.transitionService;
this.$state = $uiRouter.stateService;
this.hookDeregFns.push(this.$transitions.onRetain({ retained: function (state) { return !!_this.getDsrProp(state.self); } }, this.recordDeepState.bind(this)));
this.hookDeregFns.push(this.$transitions.onEnter({ entering: function (state) { return !!_this.getDsrProp(state.self); } }, this.recordDeepState.bind(this)));
this.hookDeregFns.push(this.$transitions.onBefore({ to: function (state) { return !!_this.getDsrProp(state.self); } }, this.deepStateRedirect.bind(this)));
}
DSRPlugin.prototype.dispose = function (router) {
this.hookDeregFns.forEach(function (fn) { return fn(); });
};
/**
* Resets deep state redirect
*
* A deep state is recorded for each DSR state.
* This function resets recorded deep state redirect(s) to the initial value.
*
* If called with no parameters, the redirects for all states are reset.
*
* If called with a `state` parameter, the redirect for that state is reset.
*
* If called with `state` and `params` parameters, the redirect for that state and set of parameter values is reset.
*
* @param state (optional) the redirect for this state will be reset
* @param params (optional) the redirect for the state and parameters will be reset
*/
DSRPlugin.prototype.reset = function (state, params) {
var $state = this.$state;
if (!state) {
$state.get().forEach(function (_state) { return delete _state.$$state().$dsr; });
}
else if (!params) {
delete $state.get(state).$$state().$dsr;
}
else {
var $$state = $state.get(state).$$state();
$$state.$dsr = $$state.$dsr.filter(this.paramsEqual($$state, params, undefined, true));
}
};
/**
* Returns the recorded redirect
*
* Returns the recorded redirect for a given DSR `state` (and optionally `params`).
*
* @param state the DSR state
* @param params (optional) the parameter values
*
* @returns the recorded redirect `TargetState`
*/
DSRPlugin.prototype.getRedirect = function (state, params) {
return this.getDeepStateRedirect(state, params);
};
DSRPlugin.prototype.getDsrProp = function (state) {
return state.deepStateRedirect || state.dsr;
}
function getConfig(state) {
var dsrProp = getDsr(state);
var propType = typeof dsrProp;
if (propType === 'undefined')
};
DSRPlugin.prototype.getConfig = function (state) {
var $state = this.$state;
var dsrProp = this.getDsrProp(state);
if (typeof dsrProp === 'undefined')
return;
var params;
var defaultTarget = propType === 'string' ? dsrProp : undefined;
var fn = propType === 'function' ? dsrProp : undefined;
if (propType === 'object') {
var defaultTarget = typeof dsrProp === 'string' ? $state.target(dsrProp) : undefined;
var fn = typeof dsrProp === 'function' ? dsrProp : undefined;
if (typeof dsrProp === 'object') {
fn = dsrProp.fn;
var defaultType = typeof dsrProp.default;
if (defaultType === 'object') {
if (typeof dsrProp.default === 'object') {
defaultTarget = $state.target(dsrProp.default.state, dsrProp.default.params, dsrProp.default.options);
}
else if (defaultType === 'string') {
else if (typeof dsrProp.default === 'string') {
defaultTarget = $state.target(dsrProp.default);
}
if (dsrProp.params === true) {
params = function () {
return true;
};
var paramsProp_1 = dsrProp.params;
if (paramsProp_1 === true) {
params = function () { return true; };
}
else if (Array.isArray(dsrProp.params)) {
params = function (param) {
return dsrProp.params.indexOf(param.id) !== -1;
};
else if (Array.isArray(paramsProp_1)) {
params = function (param) { return paramsProp_1.indexOf(param.id) !== -1; };
}
}
fn = fn || (function (transition, target) { return target; });
return { params: params, default: defaultTarget, fn: fn };
}
function paramsEqual(state, transParams, schemaMatchFn, negate) {
return { default: defaultTarget, params: params, fn: fn };
};
DSRPlugin.prototype.paramsEqual = function (state, transParams, paramPredicate, negate) {
if (paramPredicate === void 0) { paramPredicate = function () { return true; }; }
if (negate === void 0) { negate = false; }
schemaMatchFn = schemaMatchFn || (function () { return true; });
var schema = state.parameters({ inherit: true }).filter(schemaMatchFn);
var schema = state.parameters({ inherit: true }).filter(paramPredicate);
return function (redirect) {

@@ -50,5 +95,8 @@ var equals = Param.equals(schema, redirect.triggerParams, transParams);

};
}
function recordDeepState(transition, state) {
var paramsConfig = getConfig(state).params;
};
DSRPlugin.prototype.recordDeepState = function (transition, state) {
var _this = this;
var $state = this.$state;
var paramsConfig = this.getConfig(state).params;
var _state = state.$$state();
transition.promise.then(function () {

@@ -59,16 +107,18 @@ var transTo = transition.to();

if (paramsConfig) {
state.$dsr = (state.$dsr || []).filter(paramsEqual(transTo.$$state(), transParams, undefined, true));
state.$dsr.push({ triggerParams: transParams, target: recordedDsrTarget });
var recordedDSR = _state.$dsr || [];
var predicate = _this.paramsEqual(transTo.$$state(), transParams, undefined, true);
_state.$dsr = recordedDSR.filter(predicate);
_state.$dsr.push({ triggerParams: transParams, target: recordedDsrTarget });
}
else {
state.$dsr = recordedDsrTarget;
_state.$dsr = recordedDsrTarget;
}
});
}
function deepStateRedirect(transition) {
};
DSRPlugin.prototype.deepStateRedirect = function (transition) {
var opts = transition.options();
if (opts['ignoreDsr'] || (opts.custom && opts.custom.ignoreDsr))
return;
var config = getConfig(transition.to());
var redirect = getDeepStateRedirect(transition.to(), transition.params());
var config = this.getConfig(transition.to());
var redirect = this.getDeepStateRedirect(transition.to(), transition.params());
redirect = config.fn(transition, redirect);

@@ -78,14 +128,16 @@ if (redirect && redirect.state() === transition.to())

return redirect;
}
function getDeepStateRedirect(stateOrName, params) {
var state = $state.get(stateOrName);
var dsrTarget, config = getConfig(state);
var $$state = state.$$state();
};
DSRPlugin.prototype.getDeepStateRedirect = function (stateOrName, params) {
var $state = this.$state;
var _state = $state.get(stateOrName);
var state = _state && _state.$$state();
var config = this.getConfig(_state);
var dsrTarget;
if (config.params) {
var predicate = paramsEqual($$state, params, config.params, false);
var match = $$state['$dsr'] && $$state['$dsr'].filter(predicate)[0];
var predicate = this.paramsEqual(state, params, config.params, false);
var match = state.$dsr && state.$dsr.filter(predicate)[0];
dsrTarget = match && match.target;
}
else {
dsrTarget = $$state['$dsr'];
dsrTarget = state.$dsr;
}

@@ -99,23 +151,6 @@ dsrTarget = dsrTarget || config.default;

return dsrTarget;
}
return {
name: 'deep-state-redirect',
reset: function (state, params) {
if (!state) {
$state.get().forEach(function (state) { return delete state.$$state()['$dsr']; });
}
else if (!params) {
delete $state.get(state).$$state()['$dsr'];
}
else {
var $$state = $state.get(state).$$state();
$$state['$dsr'] = $$state['$dsr'].filter(paramsEqual($$state, params, null, true));
}
},
getRedirect: function (state, params) {
return getDeepStateRedirect(state, params);
},
};
}
return DSRPlugin;
}());
export { DSRPlugin };
//# sourceMappingURL=dsr.js.map

@@ -1,1 +0,1 @@

export * from "./dsr";
export * from './dsr';

@@ -1,2 +0,2 @@

export * from "./dsr";
export * from './dsr';
//# sourceMappingURL=index.js.map

@@ -1,9 +0,43 @@

import { UIRouter } from "@uirouter/core";
declare module "@uirouter/core" {
interface StateDeclaration {
dsr?: any;
deepStateRedirect?: any;
}
import { UIRouter, RawParams, StateOrName, TargetState, UIRouterPlugin, TransitionService, StateService } from '@uirouter/core';
declare class DSRPlugin implements UIRouterPlugin {
name: string;
$transitions: TransitionService;
$state: StateService;
hookDeregFns: any[];
constructor($uiRouter: UIRouter);
dispose(router: UIRouter): void;
/**
* Resets deep state redirect
*
* A deep state is recorded for each DSR state.
* This function resets recorded deep state redirect(s) to the initial value.
*
* If called with no parameters, the redirects for all states are reset.
*
* If called with a `state` parameter, the redirect for that state is reset.
*
* If called with `state` and `params` parameters, the redirect for that state and set of parameter values is reset.
*
* @param state (optional) the redirect for this state will be reset
* @param params (optional) the redirect for the state and parameters will be reset
*/
reset(state?: StateOrName, params?: RawParams): void;
/**
* Returns the recorded redirect
*
* Returns the recorded redirect for a given DSR `state` (and optionally `params`).
*
* @param state the DSR state
* @param params (optional) the parameter values
*
* @returns the recorded redirect `TargetState`
*/
getRedirect(state: StateOrName, params?: RawParams): TargetState;
private getDsrProp(state);
private getConfig(state);
private paramsEqual(state, transParams, paramPredicate?, negate?);
private recordDeepState(transition, state);
private deepStateRedirect(transition);
private getDeepStateRedirect(stateOrName, params);
}
declare function DSRPlugin($uiRouter: UIRouter): any;
export { DSRPlugin };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@uirouter/core");
function DSRPlugin($uiRouter) {
var $transitions = $uiRouter.transitionService;
var $state = $uiRouter.stateService;
$transitions.onRetain({ retained: getDsr }, recordDeepState);
$transitions.onEnter({ entering: getDsr }, recordDeepState);
$transitions.onBefore({ to: getDsr }, deepStateRedirect);
function getDsr(state) {
var DSRPlugin = /** @class */ (function () {
function DSRPlugin($uiRouter) {
var _this = this;
this.name = 'deep-state-redirect';
this.hookDeregFns = [];
this.$transitions = $uiRouter.transitionService;
this.$state = $uiRouter.stateService;
this.hookDeregFns.push(this.$transitions.onRetain({ retained: function (state) { return !!_this.getDsrProp(state.self); } }, this.recordDeepState.bind(this)));
this.hookDeregFns.push(this.$transitions.onEnter({ entering: function (state) { return !!_this.getDsrProp(state.self); } }, this.recordDeepState.bind(this)));
this.hookDeregFns.push(this.$transitions.onBefore({ to: function (state) { return !!_this.getDsrProp(state.self); } }, this.deepStateRedirect.bind(this)));
}
DSRPlugin.prototype.dispose = function (router) {
this.hookDeregFns.forEach(function (fn) { return fn(); });
};
/**
* Resets deep state redirect
*
* A deep state is recorded for each DSR state.
* This function resets recorded deep state redirect(s) to the initial value.
*
* If called with no parameters, the redirects for all states are reset.
*
* If called with a `state` parameter, the redirect for that state is reset.
*
* If called with `state` and `params` parameters, the redirect for that state and set of parameter values is reset.
*
* @param state (optional) the redirect for this state will be reset
* @param params (optional) the redirect for the state and parameters will be reset
*/
DSRPlugin.prototype.reset = function (state, params) {
var $state = this.$state;
if (!state) {
$state.get().forEach(function (_state) { return delete _state.$$state().$dsr; });
}
else if (!params) {
delete $state.get(state).$$state().$dsr;
}
else {
var $$state = $state.get(state).$$state();
$$state.$dsr = $$state.$dsr.filter(this.paramsEqual($$state, params, undefined, true));
}
};
/**
* Returns the recorded redirect
*
* Returns the recorded redirect for a given DSR `state` (and optionally `params`).
*
* @param state the DSR state
* @param params (optional) the parameter values
*
* @returns the recorded redirect `TargetState`
*/
DSRPlugin.prototype.getRedirect = function (state, params) {
return this.getDeepStateRedirect(state, params);
};
DSRPlugin.prototype.getDsrProp = function (state) {
return state.deepStateRedirect || state.dsr;
}
function getConfig(state) {
var dsrProp = getDsr(state);
var propType = typeof dsrProp;
if (propType === 'undefined')
};
DSRPlugin.prototype.getConfig = function (state) {
var $state = this.$state;
var dsrProp = this.getDsrProp(state);
if (typeof dsrProp === 'undefined')
return;
var params;
var defaultTarget = propType === 'string' ? dsrProp : undefined;
var fn = propType === 'function' ? dsrProp : undefined;
if (propType === 'object') {
var defaultTarget = typeof dsrProp === 'string' ? $state.target(dsrProp) : undefined;
var fn = typeof dsrProp === 'function' ? dsrProp : undefined;
if (typeof dsrProp === 'object') {
fn = dsrProp.fn;
var defaultType = typeof dsrProp.default;
if (defaultType === 'object') {
if (typeof dsrProp.default === 'object') {
defaultTarget = $state.target(dsrProp.default.state, dsrProp.default.params, dsrProp.default.options);
}
else if (defaultType === 'string') {
else if (typeof dsrProp.default === 'string') {
defaultTarget = $state.target(dsrProp.default);
}
if (dsrProp.params === true) {
params = function () {
return true;
};
var paramsProp_1 = dsrProp.params;
if (paramsProp_1 === true) {
params = function () { return true; };
}
else if (Array.isArray(dsrProp.params)) {
params = function (param) {
return dsrProp.params.indexOf(param.id) !== -1;
};
else if (Array.isArray(paramsProp_1)) {
params = function (param) { return paramsProp_1.indexOf(param.id) !== -1; };
}
}
fn = fn || (function (transition, target) { return target; });
return { params: params, default: defaultTarget, fn: fn };
}
function paramsEqual(state, transParams, schemaMatchFn, negate) {
return { default: defaultTarget, params: params, fn: fn };
};
DSRPlugin.prototype.paramsEqual = function (state, transParams, paramPredicate, negate) {
if (paramPredicate === void 0) { paramPredicate = function () { return true; }; }
if (negate === void 0) { negate = false; }
schemaMatchFn = schemaMatchFn || (function () { return true; });
var schema = state.parameters({ inherit: true }).filter(schemaMatchFn);
var schema = state.parameters({ inherit: true }).filter(paramPredicate);
return function (redirect) {

@@ -52,5 +97,8 @@ var equals = core_1.Param.equals(schema, redirect.triggerParams, transParams);

};
}
function recordDeepState(transition, state) {
var paramsConfig = getConfig(state).params;
};
DSRPlugin.prototype.recordDeepState = function (transition, state) {
var _this = this;
var $state = this.$state;
var paramsConfig = this.getConfig(state).params;
var _state = state.$$state();
transition.promise.then(function () {

@@ -61,16 +109,18 @@ var transTo = transition.to();

if (paramsConfig) {
state.$dsr = (state.$dsr || []).filter(paramsEqual(transTo.$$state(), transParams, undefined, true));
state.$dsr.push({ triggerParams: transParams, target: recordedDsrTarget });
var recordedDSR = _state.$dsr || [];
var predicate = _this.paramsEqual(transTo.$$state(), transParams, undefined, true);
_state.$dsr = recordedDSR.filter(predicate);
_state.$dsr.push({ triggerParams: transParams, target: recordedDsrTarget });
}
else {
state.$dsr = recordedDsrTarget;
_state.$dsr = recordedDsrTarget;
}
});
}
function deepStateRedirect(transition) {
};
DSRPlugin.prototype.deepStateRedirect = function (transition) {
var opts = transition.options();
if (opts['ignoreDsr'] || (opts.custom && opts.custom.ignoreDsr))
return;
var config = getConfig(transition.to());
var redirect = getDeepStateRedirect(transition.to(), transition.params());
var config = this.getConfig(transition.to());
var redirect = this.getDeepStateRedirect(transition.to(), transition.params());
redirect = config.fn(transition, redirect);

@@ -80,14 +130,16 @@ if (redirect && redirect.state() === transition.to())

return redirect;
}
function getDeepStateRedirect(stateOrName, params) {
var state = $state.get(stateOrName);
var dsrTarget, config = getConfig(state);
var $$state = state.$$state();
};
DSRPlugin.prototype.getDeepStateRedirect = function (stateOrName, params) {
var $state = this.$state;
var _state = $state.get(stateOrName);
var state = _state && _state.$$state();
var config = this.getConfig(_state);
var dsrTarget;
if (config.params) {
var predicate = paramsEqual($$state, params, config.params, false);
var match = $$state['$dsr'] && $$state['$dsr'].filter(predicate)[0];
var predicate = this.paramsEqual(state, params, config.params, false);
var match = state.$dsr && state.$dsr.filter(predicate)[0];
dsrTarget = match && match.target;
}
else {
dsrTarget = $$state['$dsr'];
dsrTarget = state.$dsr;
}

@@ -101,23 +153,6 @@ dsrTarget = dsrTarget || config.default;

return dsrTarget;
}
return {
name: 'deep-state-redirect',
reset: function (state, params) {
if (!state) {
$state.get().forEach(function (state) { return delete state.$$state()['$dsr']; });
}
else if (!params) {
delete $state.get(state).$$state()['$dsr'];
}
else {
var $$state = $state.get(state).$$state();
$$state['$dsr'] = $$state['$dsr'].filter(paramsEqual($$state, params, null, true));
}
},
getRedirect: function (state, params) {
return getDeepStateRedirect(state, params);
},
};
}
return DSRPlugin;
}());
exports.DSRPlugin = DSRPlugin;
//# sourceMappingURL=dsr.js.map

@@ -1,1 +0,1 @@

export * from "./dsr";
export * from './dsr';
{
"name": "@uirouter/dsr",
"description": "UI-Router Deep State Redirect: redirect to the most recently activated child state",
"version": "1.0.2",
"version": "1.0.3",
"scripts": {

@@ -9,8 +9,11 @@ "clean": "shx rm -rf lib lib-esm _bundles",

"compile": "npm run clean && tsc && tsc -m es6 --outDir lib-esm",
"prepare": "npm run build",
"test": "karma start",
"test:downstream": "test_downstream_projects --workspace",
"watch": "run-p watch:*",
"watch:buildjs": "tsc -w",
"watch:test": "karma start --singleRun=false --autoWatch=true --autoWatchInterval=1",
"debug": "karma start --singleRun=false --autoWatch=true --autoWatchInterval=1 --browsers=Chrome"
"debug": "karma start --singleRun=false --autoWatch=true --autoWatchInterval=1 --browsers=Chrome",
"changelog": "update_changelog",
"release": "release",
"prepublishOnly": "npm run build"
},

@@ -48,34 +51,26 @@ "homepage": "https://ui-router.github.io",

"devDependencies": {
"@types/jasmine": "^2.2.34",
"@types/jquery": "^1.10.31",
"@types/lodash": "^4.14.38",
"@uirouter/core": "^5.0.0",
"awesome-typescript-loader": "^3.1.3",
"conventional-changelog": "^1.1.0",
"conventional-changelog-cli": "^1.1.1",
"conventional-changelog-ui-router-core": "^1.3.0",
"core-js": "^2.4.1",
"jasmine-core": "^2.4.1",
"karma": "^1.2.0",
"karma-chrome-launcher": "~0.1.0",
"karma-coverage": "^0.5.3",
"karma-jasmine": "^1.0.2",
"karma-phantomjs-launcher": "^1.0.2",
"karma-script-launcher": "~0.1.0",
"@types/jasmine": "^2.8.6",
"@types/jquery": "^3.3.1",
"@types/lodash": "^4.14.106",
"@uirouter/core": "^5.0.17",
"@uirouter/publish-scripts": "^2.3.2",
"jasmine-core": "^3.1.0",
"karma": "^2.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-jasmine": "^1.1.1",
"karma-mocha-reporter": "^2.2.5",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^1.8.0",
"lodash": "^4.16.6",
"npm-run-all": "^3.1.1",
"readline-sync": "^1.4.4",
"rollup": "^0.41.6",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-progress": "^0.2.1",
"karma-super-dots-reporter": "^0.1.0",
"karma-webpack": "^3.0.0",
"lodash": "^4.17.5",
"rollup": "^0.57.1",
"rollup-plugin-node-resolve": "^3.3.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-uglify": "^1.0.2",
"shelljs": "^0.7.0",
"shx": "^0.1.4",
"tslint": "=2.5.0",
"typescript": "^2.3.0",
"webpack": "^1.13.3"
"rollup-plugin-uglify": "^3.0.0",
"ts-loader": "^4.1.0",
"tslint": "5.9.1",
"tslint-eslint-rules": "^5.1.0",
"typescript": "^2.8.1",
"webpack": "^4.4.1"
}
}
# Deep State Redirect
[![Greenkeeper badge](https://badges.greenkeeper.io/ui-router/dsr.svg)](https://greenkeeper.io/)
### DSR for UI-Router 1.0  [![Build Status](https://travis-ci.org/christopherthielen/deep-state-redirect.svg?branch=master)](https://travis-ci.org/christopherthielen/deep-state-redirect)

@@ -4,0 +6,0 @@

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