Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

navi

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

navi - npm Package Compare versions

Comparing version 0.7.0 to 0.7.1

dist/commonjs/app.d.ts

17

dist/commonjs/BrowserNavigation.d.ts

@@ -29,4 +29,9 @@ import { History } from 'history';

disableScrollHandling?: boolean;
initialRootContext?: Context;
rootSwitch: Switch;
/**
* The scroll behavior to use when scrolling between hashes on a
* page. Defaults to smooth.
*/
hashScrollBehavior?: 'smooth' | 'instant';
initialContext?: Context;
pages: Switch;
rootPath?: string;

@@ -40,3 +45,3 @@ }

private disableScrollHandling;
private rootSwitch;
private pages;
private rootPath?;

@@ -46,7 +51,9 @@ private resolver;

private renderedRoute?;
private hashScrollBehavior;
private currentRouteObservable;
constructor(options: BrowserNavigationOptions<Context>);
setContext(context: Context): void;
getSnapshot(): NavigationSnapshot;
getSteadySnapshot(): Promise<NavigationSnapshot>;
getCurrentValue(): NavigationSnapshot;
steady(): Promise<void>;
getSteadyValue(): Promise<NavigationSnapshot>;
/**

@@ -53,0 +60,0 @@ * If you're using code splitting, you'll need to subscribe to changes to

@@ -71,3 +71,5 @@ "use strict";

prevRoute.url.pathname !== nextRoute.url.pathname)) {
scrollToHash(nextRoute.url.hash);
scrollToHash(nextRoute.url.hash, prevRoute && prevRoute.url && prevRoute.url.pathname === nextRoute.url.pathname
? _this.hashScrollBehavior
: 'instant');
}

@@ -77,10 +79,15 @@ }

}
else {
if (_this.receivedRoute.url.hash) {
scrollToHash(_this.receivedRoute.url.hash, _this.hashScrollBehavior);
}
}
};
this.history = options.history || history_1.createBrowserHistory();
this.resolver = new Resolver_1.Resolver;
this.rootSwitch = options.rootSwitch;
this.pages = options.pages;
this.rootPath = options.rootPath;
this.router = new Router_1.Router(this.resolver, {
rootContext: options.initialRootContext,
rootSwitch: options.rootSwitch,
rootContext: options.initialContext,
pages: options.pages,
rootPath: options.rootPath,

@@ -98,2 +105,3 @@ });

this.renderedRoute = this.currentRouteObservable.getValue();
this.hashScrollBehavior = options.hashScrollBehavior || 'smooth';
}

@@ -103,3 +111,3 @@ BrowserNavigation.prototype.setContext = function (context) {

rootContext: context,
rootSwitch: this.rootSwitch,
pages: this.pages,
rootPath: this.rootPath,

@@ -109,3 +117,3 @@ });

};
BrowserNavigation.prototype.getSnapshot = function () {
BrowserNavigation.prototype.getCurrentValue = function () {
var route = this.currentRouteObservable.getValue();

@@ -120,4 +128,16 @@ return {

};
BrowserNavigation.prototype.getSteadySnapshot = function () {
BrowserNavigation.prototype.steady = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.getSteadyValue()];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
BrowserNavigation.prototype.getSteadyValue = function () {
return __awaiter(this, void 0, void 0, function () {
var _this = this;

@@ -147,3 +167,3 @@ return __generator(this, function (_a) {

exports.BrowserNavigation = BrowserNavigation;
function scrollToHash(hash) {
function scrollToHash(hash, behavior) {
if (hash) {

@@ -153,3 +173,3 @@ var id = document.getElementById(hash.slice(1));

id.scrollIntoView({
behavior: 'instant',
behavior: behavior,
block: 'start'

@@ -156,0 +176,0 @@ });

@@ -140,4 +140,7 @@ "use strict";

CurrentRouteObservable.prototype.handleURLChange = function (url, force) {
// Defuse history update loops
// Bail without change is the URL hasn't changed
if (!force && this.lastReceivedURL && URLTools_1.areURLDescriptorsEqual(this.lastReceivedURL, url)) {
for (var i = 0; i < this.observers.length; i++) {
this.observers[i].next(this.lastRoute);
}
return;

@@ -144,0 +147,0 @@ }

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

export { app } from './app';
export { createContext, Context } from './Context';

@@ -2,0 +3,0 @@ export { Env } from './Env';

@@ -6,2 +6,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var app_1 = require("./app");
exports.app = app_1.app;
var Context_1 = require("./Context");

@@ -8,0 +10,0 @@ exports.createContext = Context_1.createContext;

@@ -9,4 +9,4 @@ import { History } from 'history';

url: string | Partial<URLDescriptor>;
initialRootContext?: Context;
rootSwitch: Switch;
initialContext?: Context;
pages: Switch;
rootPath?: string;

@@ -18,3 +18,3 @@ }

readonly history: History;
private rootSwitch;
private pages;
private rootPath?;

@@ -25,4 +25,4 @@ private resolver;

setContext(context: Context): void;
getSnapshot(): NavigationSnapshot;
getSteadySnapshot(): Promise<NavigationSnapshot>;
getCurrentValue(): NavigationSnapshot;
getSteadyValue(): Promise<NavigationSnapshot>;
/**

@@ -29,0 +29,0 @@ * If you're using code splitting, you'll need to subscribe to changes to

@@ -54,7 +54,7 @@ "use strict";

this.resolver = new Resolver_1.Resolver;
this.rootSwitch = options.rootSwitch;
this.pages = options.pages;
this.rootPath = options.rootPath;
this.router = new Router_1.Router(this.resolver, {
rootContext: options.initialRootContext,
rootSwitch: this.rootSwitch,
rootContext: options.initialContext,
pages: this.pages,
rootPath: this.rootPath,

@@ -70,3 +70,3 @@ });

rootContext: context,
rootSwitch: this.rootSwitch,
pages: this.pages,
rootPath: this.rootPath,

@@ -76,3 +76,3 @@ });

};
MemoryNavigation.prototype.getSnapshot = function () {
MemoryNavigation.prototype.getCurrentValue = function () {
var route = this.currentRouteObservable.getValue();

@@ -87,3 +87,3 @@ return {

};
MemoryNavigation.prototype.getSteadySnapshot = function () {
MemoryNavigation.prototype.getSteadyValue = function () {
return __awaiter(this, void 0, void 0, function () {

@@ -90,0 +90,0 @@ var _this = this;

@@ -10,3 +10,3 @@ import { History } from 'history';

setContext(context: Context): void;
getSnapshot(): NavigationSnapshot;
getCurrentValue(): NavigationSnapshot;
/**

@@ -17,3 +17,3 @@ * Returns a promise that resolves once `isReady()` returns true.

*/
getSteadySnapshot(): Promise<NavigationSnapshot>;
getSteadyValue(): Promise<NavigationSnapshot>;
}

@@ -20,0 +20,0 @@ export interface NavigationSnapshot {

@@ -11,3 +11,3 @@ import { URLDescriptor } from './URLTools';

private rootContext;
private rootSwitch;
private pages;
private rootMapping;

@@ -20,3 +20,3 @@ private observers;

private queueItems;
constructor(url: URLDescriptor, rootContext: any, rootSwitch: Switch, rootMapping: Mapping, resolver: Resolver, router: Router, options: RouterMapOptions);
constructor(url: URLDescriptor, rootContext: any, pages: Switch, rootMapping: Mapping, resolver: Resolver, router: Router, options: RouterMapOptions);
subscribe(onNextOrObserver: Observer<RouteMap> | ((value: RouteMap) => void), onError?: (error: any) => void, onComplete?: () => void): SimpleSubscription;

@@ -23,0 +23,0 @@ private handleUnsubscribe;

@@ -12,3 +12,3 @@ "use strict";

var RouteMapObservable = /** @class */ (function () {
function RouteMapObservable(url, rootContext, rootSwitch, rootMapping, resolver, router, options) {
function RouteMapObservable(url, rootContext, pages, rootMapping, resolver, router, options) {
var _this = this;

@@ -109,3 +109,3 @@ this.handleUnsubscribe = function (observer) {

this.rootContext = rootContext;
this.rootSwitch = rootSwitch;
this.pages = pages;
this.rootMapping = rootMapping;

@@ -160,3 +160,3 @@ this.options = options;

depth: depth,
matcher: new this.rootSwitch({
matcher: new this.pages({
appendFinalSlash: false,

@@ -163,0 +163,0 @@ env: matchEnv,

@@ -13,3 +13,3 @@ import { Route } from './Route';

private resolver;
constructor(url: URLDescriptor, env: Env, rootSwitch: Switch, resolver: Resolver, withContent: boolean);
constructor(url: URLDescriptor, env: Env, pages: Switch, resolver: Resolver, withContent: boolean);
subscribe(onNextOrObserver: Observer<Route> | ((value: Route) => void), onError?: (error: any) => void, onComplete?: () => void): SimpleSubscription;

@@ -16,0 +16,0 @@ private handleUnsubscribe;

@@ -6,3 +6,3 @@ "use strict";

var RouteObservable = /** @class */ (function () {
function RouteObservable(url, env, rootSwitch, resolver, withContent) {
function RouteObservable(url, env, pages, resolver, withContent) {
var _this = this;

@@ -39,3 +39,3 @@ this.handleUnsubscribe = function (observer) {

this.observers = [];
this.matcher = new rootSwitch({
this.matcher = new pages({
appendFinalSlash: true,

@@ -42,0 +42,0 @@ env: env,

@@ -12,3 +12,3 @@ import { Switch } from './Switch';

rootContext?: Context;
rootSwitch: Switch;
pages: Switch;
rootPath?: string;

@@ -30,3 +30,3 @@ }

private rootContext;
private rootSwitch;
private pages;
private rootMapping;

@@ -33,0 +33,0 @@ constructor(resolver: Resolver, options: RouterOptions<Context>);

@@ -21,4 +21,4 @@ "use strict";

if (process.env.NODE_ENV !== "production") {
if (!options.rootSwitch || options.rootSwitch.type !== Node_1.NaviNodeType.Switch) {
throw new Error("Expected to receive a Switch object for the \"rootSwitch\" prop, but instead received \"" + options.rootSwitch + "\".");
if (!options.pages || options.pages.type !== Node_1.NaviNodeType.Switch) {
throw new Error("Expected to receive a Switch object for the \"pages\" prop, but instead received \"" + options.pages + "\".");
}

@@ -28,4 +28,4 @@ }

this.rootContext = options.rootContext || {};
this.rootSwitch = options.rootSwitch;
this.rootMapping = Mapping_1.createRootMapping(options.rootSwitch, options.rootPath);
this.pages = options.pages;
this.rootMapping = Mapping_1.createRootMapping(options.pages, options.rootPath);
}

@@ -48,3 +48,3 @@ Router.prototype.createObservable = function (urlOrDescriptor, options) {

if (matchEnv) {
return new RouteObservable_1.RouteObservable(url, matchEnv, this.rootSwitch, this.resolver, !!options.withContent);
return new RouteObservable_1.RouteObservable(url, matchEnv, this.pages, this.resolver, !!options.withContent);
}

@@ -54,3 +54,3 @@ };

if (options === void 0) { options = {}; }
return new RouteMapObservable_1.RouteMapObservable(URLTools_1.createURLDescriptor(urlOrDescriptor, { ensureTrailingSlash: false }), this.rootContext, this.rootSwitch, this.rootMapping, this.resolver, this, options);
return new RouteMapObservable_1.RouteMapObservable(URLTools_1.createURLDescriptor(urlOrDescriptor, { ensureTrailingSlash: false }), this.rootContext, this.pages, this.rootMapping, this.resolver, this, options);
};

@@ -57,0 +57,0 @@ Router.prototype.resolve = function (urls, options) {

@@ -29,4 +29,9 @@ import { History } from 'history';

disableScrollHandling?: boolean;
initialRootContext?: Context;
rootSwitch: Switch;
/**
* The scroll behavior to use when scrolling between hashes on a
* page. Defaults to smooth.
*/
hashScrollBehavior?: 'smooth' | 'instant';
initialContext?: Context;
pages: Switch;
rootPath?: string;

@@ -40,3 +45,3 @@ }

private disableScrollHandling;
private rootSwitch;
private pages;
private rootPath?;

@@ -46,7 +51,9 @@ private resolver;

private renderedRoute?;
private hashScrollBehavior;
private currentRouteObservable;
constructor(options: BrowserNavigationOptions<Context>);
setContext(context: Context): void;
getSnapshot(): NavigationSnapshot;
getSteadySnapshot(): Promise<NavigationSnapshot>;
getCurrentValue(): NavigationSnapshot;
steady(): Promise<void>;
getSteadyValue(): Promise<NavigationSnapshot>;
/**

@@ -53,0 +60,0 @@ * If you're using code splitting, you'll need to subscribe to changes to

@@ -68,3 +68,5 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

prevRoute.url.pathname !== nextRoute.url.pathname)) {
scrollToHash(nextRoute.url.hash);
scrollToHash(nextRoute.url.hash, prevRoute && prevRoute.url && prevRoute.url.pathname === nextRoute.url.pathname
? _this.hashScrollBehavior
: 'instant');
}

@@ -74,10 +76,15 @@ }

}
else {
if (_this.receivedRoute.url.hash) {
scrollToHash(_this.receivedRoute.url.hash, _this.hashScrollBehavior);
}
}
};
this.history = options.history || createBrowserHistory();
this.resolver = new Resolver;
this.rootSwitch = options.rootSwitch;
this.pages = options.pages;
this.rootPath = options.rootPath;
this.router = new Router(this.resolver, {
rootContext: options.initialRootContext,
rootSwitch: options.rootSwitch,
rootContext: options.initialContext,
pages: options.pages,
rootPath: options.rootPath,

@@ -95,2 +102,3 @@ });

this.renderedRoute = this.currentRouteObservable.getValue();
this.hashScrollBehavior = options.hashScrollBehavior || 'smooth';
}

@@ -100,3 +108,3 @@ BrowserNavigation.prototype.setContext = function (context) {

rootContext: context,
rootSwitch: this.rootSwitch,
pages: this.pages,
rootPath: this.rootPath,

@@ -106,3 +114,3 @@ });

};
BrowserNavigation.prototype.getSnapshot = function () {
BrowserNavigation.prototype.getCurrentValue = function () {
var route = this.currentRouteObservable.getValue();

@@ -117,4 +125,16 @@ return {

};
BrowserNavigation.prototype.getSteadySnapshot = function () {
BrowserNavigation.prototype.steady = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.getSteadyValue()];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
BrowserNavigation.prototype.getSteadyValue = function () {
return __awaiter(this, void 0, void 0, function () {
var _this = this;

@@ -144,3 +164,3 @@ return __generator(this, function (_a) {

export { BrowserNavigation };
function scrollToHash(hash) {
function scrollToHash(hash, behavior) {
if (hash) {

@@ -150,3 +170,3 @@ var id = document.getElementById(hash.slice(1));

id.scrollIntoView({
behavior: 'instant',
behavior: behavior,
block: 'start'

@@ -153,0 +173,0 @@ });

@@ -137,4 +137,7 @@ var __assign = (this && this.__assign) || Object.assign || function(t) {

CurrentRouteObservable.prototype.handleURLChange = function (url, force) {
// Defuse history update loops
// Bail without change is the URL hasn't changed
if (!force && this.lastReceivedURL && areURLDescriptorsEqual(this.lastReceivedURL, url)) {
for (var i = 0; i < this.observers.length; i++) {
this.observers[i].next(this.lastRoute);
}
return;

@@ -141,0 +144,0 @@ }

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

export { app } from './app';
export { createContext, Context } from './Context';

@@ -2,0 +3,0 @@ export { Env } from './Env';

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

export { app } from './app';
export { createContext } from './Context';

@@ -2,0 +3,0 @@ export { createSwitch } from './Switch';

@@ -9,4 +9,4 @@ import { History } from 'history';

url: string | Partial<URLDescriptor>;
initialRootContext?: Context;
rootSwitch: Switch;
initialContext?: Context;
pages: Switch;
rootPath?: string;

@@ -18,3 +18,3 @@ }

readonly history: History;
private rootSwitch;
private pages;
private rootPath?;

@@ -25,4 +25,4 @@ private resolver;

setContext(context: Context): void;
getSnapshot(): NavigationSnapshot;
getSteadySnapshot(): Promise<NavigationSnapshot>;
getCurrentValue(): NavigationSnapshot;
getSteadyValue(): Promise<NavigationSnapshot>;
/**

@@ -29,0 +29,0 @@ * If you're using code splitting, you'll need to subscribe to changes to

@@ -51,7 +51,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

this.resolver = new Resolver;
this.rootSwitch = options.rootSwitch;
this.pages = options.pages;
this.rootPath = options.rootPath;
this.router = new Router(this.resolver, {
rootContext: options.initialRootContext,
rootSwitch: this.rootSwitch,
rootContext: options.initialContext,
pages: this.pages,
rootPath: this.rootPath,

@@ -67,3 +67,3 @@ });

rootContext: context,
rootSwitch: this.rootSwitch,
pages: this.pages,
rootPath: this.rootPath,

@@ -73,3 +73,3 @@ });

};
MemoryNavigation.prototype.getSnapshot = function () {
MemoryNavigation.prototype.getCurrentValue = function () {
var route = this.currentRouteObservable.getValue();

@@ -84,3 +84,3 @@ return {

};
MemoryNavigation.prototype.getSteadySnapshot = function () {
MemoryNavigation.prototype.getSteadyValue = function () {
return __awaiter(this, void 0, void 0, function () {

@@ -87,0 +87,0 @@ var _this = this;

@@ -10,3 +10,3 @@ import { History } from 'history';

setContext(context: Context): void;
getSnapshot(): NavigationSnapshot;
getCurrentValue(): NavigationSnapshot;
/**

@@ -17,3 +17,3 @@ * Returns a promise that resolves once `isReady()` returns true.

*/
getSteadySnapshot(): Promise<NavigationSnapshot>;
getSteadyValue(): Promise<NavigationSnapshot>;
}

@@ -20,0 +20,0 @@ export interface NavigationSnapshot {

@@ -11,3 +11,3 @@ import { URLDescriptor } from './URLTools';

private rootContext;
private rootSwitch;
private pages;
private rootMapping;

@@ -20,3 +20,3 @@ private observers;

private queueItems;
constructor(url: URLDescriptor, rootContext: any, rootSwitch: Switch, rootMapping: Mapping, resolver: Resolver, router: Router, options: RouterMapOptions);
constructor(url: URLDescriptor, rootContext: any, pages: Switch, rootMapping: Mapping, resolver: Resolver, router: Router, options: RouterMapOptions);
subscribe(onNextOrObserver: Observer<RouteMap> | ((value: RouteMap) => void), onError?: (error: any) => void, onComplete?: () => void): SimpleSubscription;

@@ -23,0 +23,0 @@ private handleUnsubscribe;

@@ -10,3 +10,3 @@ import { createURLDescriptor, joinPaths } from './URLTools';

var RouteMapObservable = /** @class */ (function () {
function RouteMapObservable(url, rootContext, rootSwitch, rootMapping, resolver, router, options) {
function RouteMapObservable(url, rootContext, pages, rootMapping, resolver, router, options) {
var _this = this;

@@ -107,3 +107,3 @@ this.handleUnsubscribe = function (observer) {

this.rootContext = rootContext;
this.rootSwitch = rootSwitch;
this.pages = pages;
this.rootMapping = rootMapping;

@@ -158,3 +158,3 @@ this.options = options;

depth: depth,
matcher: new this.rootSwitch({
matcher: new this.pages({
appendFinalSlash: false,

@@ -161,0 +161,0 @@ env: matchEnv,

@@ -13,3 +13,3 @@ import { Route } from './Route';

private resolver;
constructor(url: URLDescriptor, env: Env, rootSwitch: Switch, resolver: Resolver, withContent: boolean);
constructor(url: URLDescriptor, env: Env, pages: Switch, resolver: Resolver, withContent: boolean);
subscribe(onNextOrObserver: Observer<Route> | ((value: Route) => void), onError?: (error: any) => void, onComplete?: () => void): SimpleSubscription;

@@ -16,0 +16,0 @@ private handleUnsubscribe;

import { createRoute } from './Route';
import { SimpleSubscription, createOrPassthroughObserver } from './Observable';
var RouteObservable = /** @class */ (function () {
function RouteObservable(url, env, rootSwitch, resolver, withContent) {
function RouteObservable(url, env, pages, resolver, withContent) {
var _this = this;

@@ -36,3 +36,3 @@ this.handleUnsubscribe = function (observer) {

this.observers = [];
this.matcher = new rootSwitch({
this.matcher = new pages({
appendFinalSlash: true,

@@ -39,0 +39,0 @@ env: env,

@@ -12,3 +12,3 @@ import { Switch } from './Switch';

rootContext?: Context;
rootSwitch: Switch;
pages: Switch;
rootPath?: string;

@@ -30,3 +30,3 @@ }

private rootContext;
private rootSwitch;
private pages;
private rootMapping;

@@ -33,0 +33,0 @@ constructor(resolver: Resolver, options: RouterOptions<Context>);

@@ -18,4 +18,4 @@ import { createRootMapping, matchMappingAgainstPathname } from './Mapping';

if (process.env.NODE_ENV !== "production") {
if (!options.rootSwitch || options.rootSwitch.type !== NaviNodeType.Switch) {
throw new Error("Expected to receive a Switch object for the \"rootSwitch\" prop, but instead received \"" + options.rootSwitch + "\".");
if (!options.pages || options.pages.type !== NaviNodeType.Switch) {
throw new Error("Expected to receive a Switch object for the \"pages\" prop, but instead received \"" + options.pages + "\".");
}

@@ -25,4 +25,4 @@ }

this.rootContext = options.rootContext || {};
this.rootSwitch = options.rootSwitch;
this.rootMapping = createRootMapping(options.rootSwitch, options.rootPath);
this.pages = options.pages;
this.rootMapping = createRootMapping(options.pages, options.rootPath);
}

@@ -45,3 +45,3 @@ Router.prototype.createObservable = function (urlOrDescriptor, options) {

if (matchEnv) {
return new RouteObservable(url, matchEnv, this.rootSwitch, this.resolver, !!options.withContent);
return new RouteObservable(url, matchEnv, this.pages, this.resolver, !!options.withContent);
}

@@ -51,3 +51,3 @@ };

if (options === void 0) { options = {}; }
return new RouteMapObservable(createURLDescriptor(urlOrDescriptor, { ensureTrailingSlash: false }), this.rootContext, this.rootSwitch, this.rootMapping, this.resolver, this, options);
return new RouteMapObservable(createURLDescriptor(urlOrDescriptor, { ensureTrailingSlash: false }), this.rootContext, this.pages, this.rootMapping, this.resolver, this, options);
};

@@ -54,0 +54,0 @@ Router.prototype.resolve = function (urls, options) {

{
"name": "navi",
"version": "0.7.0",
"version": "0.7.1",
"description": "Junction-based routing for JavaScript.",

@@ -34,6 +34,5 @@ "author": "James K Nelson <james@jamesknelson.com>",

"devDependencies": {
"@types/jest": "^22.1.0",
"@types/jest": "^23.3.7",
"cross-env": "^5.0.5",
"history": "^4.7.2",
"jest": "^22.1.4",
"jest": "^23.6.0",
"rimraf": "^2.6.2",

@@ -43,3 +42,5 @@ "rollup": "^0.50.0",

"rollup-plugin-node-resolve": "^3.0.0",
"ts-jest": "^22.0.1",
"rollup-plugin-replace": "^2.1.0",
"rollup-plugin-uglify": "^6.0.0",
"ts-jest": "^23.10.4",
"typescript": "2.8.1"

@@ -52,17 +53,17 @@ },

"jest": {
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"testEnvironment": "node",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"json",
"jsx",
"json"
"ts",
"tsx"
],
"preset": "ts-jest",
"testMatch": null,
"globals": {
"ts-jest": {
"skipBabel": true
"babelConfig": null,
"diagnostics": false
}

@@ -69,0 +70,0 @@ }

@@ -9,3 +9,3 @@ /**

import replace from 'rollup-plugin-replace'
import uglify from 'rollup-plugin-uglify'
import { uglify } from 'rollup-plugin-uglify'

@@ -12,0 +12,0 @@ const env = process.env.NODE_ENV

@@ -38,5 +38,11 @@ import { createBrowserHistory, History } from 'history';

initialRootContext?: Context,
/**
* The scroll behavior to use when scrolling between hashes on a
* page. Defaults to smooth.
*/
hashScrollBehavior?: 'smooth' | 'instant'
rootSwitch: Switch,
initialContext?: Context,
pages: Switch,
rootPath?: string,

@@ -59,3 +65,3 @@ }

private rootSwitch: Switch
private pages: Switch
private rootPath?: string

@@ -65,2 +71,3 @@ private resolver: Resolver

private renderedRoute?: Route
private hashScrollBehavior: 'smooth' | 'instant'
private currentRouteObservable: CurrentRouteObservable<Context>

@@ -71,7 +78,7 @@

this.resolver = new Resolver
this.rootSwitch = options.rootSwitch
this.pages = options.pages
this.rootPath = options.rootPath
this.router = new Router(this.resolver, {
rootContext: options.initialRootContext,
rootSwitch: options.rootSwitch,
rootContext: options.initialContext,
pages: options.pages,
rootPath: options.rootPath,

@@ -91,2 +98,3 @@ })

this.renderedRoute = this.currentRouteObservable.getValue()
this.hashScrollBehavior = options.hashScrollBehavior || 'smooth'
}

@@ -97,3 +105,3 @@

rootContext: context,
rootSwitch: this.rootSwitch,
pages: this.pages,
rootPath: this.rootPath,

@@ -104,3 +112,3 @@ })

getSnapshot(): NavigationSnapshot {
getCurrentValue(): NavigationSnapshot {
let route = this.currentRouteObservable.getValue()

@@ -116,3 +124,8 @@ return {

async getSteadySnapshot(): Promise<NavigationSnapshot> {
async steady() {
await this.getSteadyValue()
return
}
async getSteadyValue(): Promise<NavigationSnapshot> {
return this.currentRouteObservable.getSteadyRoute().then(route => ({

@@ -165,3 +178,8 @@ route,

) {
scrollToHash(nextRoute.url.hash)
scrollToHash(
nextRoute.url.hash,
prevRoute && prevRoute.url && prevRoute.url.pathname === nextRoute.url.pathname
? this.hashScrollBehavior
: 'instant'
)
}

@@ -172,2 +190,7 @@ }

}
else {
if (this.receivedRoute.url.hash) {
scrollToHash(this.receivedRoute.url.hash, this.hashScrollBehavior)
}
}
}

@@ -177,3 +200,3 @@ }

function scrollToHash(hash) {
function scrollToHash(hash, behavior) {
if (hash) {

@@ -183,3 +206,3 @@ let id = document.getElementById(hash.slice(1))

id.scrollIntoView({
behavior: 'instant',
behavior: behavior,
block: 'start'

@@ -186,0 +209,0 @@ })

@@ -109,5 +109,8 @@ import { History } from 'history'

private handleURLChange(url: URLDescriptor, force?: boolean) {
// Defuse history update loops
// Bail without change is the URL hasn't changed
if (!force && this.lastReceivedURL && areURLDescriptorsEqual(this.lastReceivedURL, url)) {
return
for (let i = 0; i < this.observers.length; i++) {
this.observers[i].next(this.lastRoute)
}
return
}

@@ -114,0 +117,0 @@ this.lastReceivedURL = url

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

export { app } from './app'
export { createContext, Context } from './Context'

@@ -17,2 +18,2 @@ export { Env } from './Env'

export { createMemoryNavigation, MemoryNavigation } from './MemoryNavigation'
export { Observer, Subscription } from './Observable'
export { Observer, Subscription } from './Observable'

@@ -15,5 +15,5 @@ import { createMemoryHistory, History } from 'history';

initialRootContext?: Context,
initialContext?: Context,
rootSwitch: Switch,
pages: Switch,
rootPath?: string,

@@ -33,3 +33,3 @@ }

private rootSwitch: Switch
private pages: Switch
private rootPath?: string

@@ -45,7 +45,7 @@ private resolver: Resolver

this.resolver = new Resolver
this.rootSwitch = options.rootSwitch
this.pages = options.pages
this.rootPath = options.rootPath
this.router = new Router(this.resolver, {
rootContext: options.initialRootContext,
rootSwitch: this.rootSwitch,
rootContext: options.initialContext,
pages: this.pages,
rootPath: this.rootPath,

@@ -62,3 +62,3 @@ })

rootContext: context,
rootSwitch: this.rootSwitch,
pages: this.pages,
rootPath: this.rootPath,

@@ -69,3 +69,3 @@ })

getSnapshot(): NavigationSnapshot {
getCurrentValue(): NavigationSnapshot {
let route = this.currentRouteObservable.getValue()

@@ -81,3 +81,3 @@ return {

async getSteadySnapshot(): Promise<NavigationSnapshot> {
async getSteadyValue(): Promise<NavigationSnapshot> {
return this.currentRouteObservable.getSteadyRoute().then(route => ({

@@ -84,0 +84,0 @@ route,

@@ -13,3 +13,3 @@ import { History } from 'history'

getSnapshot(): NavigationSnapshot;
getCurrentValue(): NavigationSnapshot;

@@ -21,3 +21,3 @@ /**

*/
getSteadySnapshot(): Promise<NavigationSnapshot>;
getSteadyValue(): Promise<NavigationSnapshot>;
}

@@ -24,0 +24,0 @@

@@ -35,3 +35,3 @@ import { URLDescriptor, createURLDescriptor, joinPaths } from './URLTools'

private rootContext: any
private rootSwitch: Switch
private pages: Switch
private rootMapping: Mapping

@@ -49,3 +49,3 @@ private observers: Observer<RouteMap>[]

rootContext: any,
rootSwitch: Switch,
pages: Switch,
rootMapping: Mapping,

@@ -62,3 +62,3 @@ resolver: Resolver,

this.rootContext = rootContext
this.rootSwitch = rootSwitch
this.pages = pages
this.rootMapping = rootMapping

@@ -248,3 +248,3 @@ this.options = options

depth,
matcher: new this.rootSwitch({
matcher: new this.pages({
appendFinalSlash: false,

@@ -251,0 +251,0 @@ env: matchEnv,

@@ -20,3 +20,3 @@ import { Route, createRoute } from './Route'

env: Env,
rootSwitch: Switch,
pages: Switch,
resolver: Resolver,

@@ -28,3 +28,3 @@ withContent: boolean

this.observers = []
this.matcher = new rootSwitch({
this.matcher = new pages({
appendFinalSlash: true,

@@ -31,0 +31,0 @@ env,

@@ -18,3 +18,3 @@ import { Switch } from './Switch'

rootContext?: Context,
rootSwitch: Switch,
pages: Switch,
rootPath?: string,

@@ -44,3 +44,3 @@ }

private rootContext: Context
private rootSwitch: Switch<any, any, Context>
private pages: Switch<any, any, Context>
private rootMapping: Mapping

@@ -50,4 +50,4 @@

if (process.env.NODE_ENV !== "production") {
if (!options.rootSwitch || options.rootSwitch.type !== NaviNodeType.Switch) {
throw new Error(`Expected to receive a Switch object for the "rootSwitch" prop, but instead received "${options.rootSwitch}".`)
if (!options.pages || options.pages.type !== NaviNodeType.Switch) {
throw new Error(`Expected to receive a Switch object for the "pages" prop, but instead received "${options.pages}".`)
}

@@ -58,4 +58,4 @@ }

this.rootContext = options.rootContext || {} as any
this.rootSwitch = options.rootSwitch
this.rootMapping = createRootMapping(options.rootSwitch, options.rootPath)
this.pages = options.pages
this.rootMapping = createRootMapping(options.pages, options.rootPath)
}

@@ -81,3 +81,3 @@

matchEnv,
this.rootSwitch,
this.pages,
this.resolver,

@@ -93,3 +93,3 @@ !!options.withContent,

this.rootContext,
this.rootSwitch,
this.pages,
this.rootMapping,

@@ -96,0 +96,0 @@ this.resolver,

@@ -8,3 +8,3 @@ import { SwitchSegment, createMemoryNavigation, PageSegment, Status, SegmentType, NotFoundError } from '../src'

url: initialURL,
rootSwitch: fixtureSwitch,
pages: fixtureSwitch,
})

@@ -16,3 +16,3 @@ }

let { route } = await nav.getSteadySnapshot()
let { route } = await nav.getSteadyValue()
let firstSegment = route.firstSegment

@@ -34,3 +34,3 @@ let pageSegment = route.lastSegment as PageSegment

firstSegment = nav.getSnapshot().route.firstSegment
firstSegment = nav.getCurrentValue().route.firstSegment
let secondSegment = firstSegment.nextSegment

@@ -43,3 +43,3 @@

route = (await nav.getSteadySnapshot()).route
route = (await nav.getSteadyValue()).route
firstSegment = route.firstSegment

@@ -57,3 +57,3 @@ pageSegment = route.lastSegment as PageSegment

route = (await nav.getSteadySnapshot()).route
route = (await nav.getSteadyValue()).route
firstSegment = route.firstSegment

@@ -66,3 +66,3 @@ pageSegment = firstSegment.lastRemainingSegment as PageSegment

route = (await nav.getSteadySnapshot()).route
route = (await nav.getSteadyValue()).route
firstSegment = route.firstSegment

@@ -78,3 +78,3 @@ let junctionSegment = firstSegment.lastRemainingSegment as SwitchSegment

let { route } = await nav.getSteadySnapshot()
let { route } = await nav.getSteadyValue()

@@ -81,0 +81,0 @@ expect(Object.keys(route.lastSegment.content)).toEqual(['/examples/advanced/', '/examples/basic/'])

import { createSwitch, createPage, NotFoundError, createMemoryNavigation } from '../src'
describe("pageMap", () => {
const rootSwitch = createSwitch({
const pages = createSwitch({
paths: {

@@ -18,4 +18,4 @@ '/declared/:id': createPage({

test("accessing a undeclared path results in a NotFoundError", async () => {
let navi = createMemoryNavigation({ rootSwitch, url: '/undeclared' })
let { route } = await navi.getSteadySnapshot()
let navi = createMemoryNavigation({ pages, url: '/undeclared' })
let { route } = await navi.getSteadyValue()
expect(route.error).toBeInstanceOf(NotFoundError)

@@ -26,4 +26,4 @@ expect(route.error.pathname).toBe('/undeclared/')

test("getContent can choose not to throw a NotFoundError", async () => {
let navi = createMemoryNavigation({ rootSwitch, url: '/declared/1' })
let { route } = await navi.getSteadySnapshot()
let navi = createMemoryNavigation({ pages, url: '/declared/1' })
let { route } = await navi.getSteadyValue()
expect(route.error).toBeFalsy()

@@ -33,4 +33,4 @@ })

test("accessing a declared path that throws NotFoundError results in a NotFoundError", async () => {
let navi = createMemoryNavigation({ rootSwitch, url: '/declared/2' })
let { route } = await navi.getSteadySnapshot()
let navi = createMemoryNavigation({ pages, url: '/declared/2' })
let { route } = await navi.getSteadyValue()
expect(route.error).toBeInstanceOf(NotFoundError)

@@ -37,0 +37,0 @@ expect(route.error.pathname).toBe('/declared/2/')

@@ -6,3 +6,3 @@ import { createRouter } from '../src'

test("mapping over '/' returns full site", async () => {
let router = createRouter({ rootSwitch: fixtureSwitch })
let router = createRouter({ pages: fixtureSwitch })
let map = await router.resolvePageMap('/')

@@ -13,3 +13,3 @@ expect(Object.keys(map).length).toBe(4)

test("mapping over '' returns full site", async () => {
let router = createRouter({ rootSwitch: fixtureSwitch })
let router = createRouter({ pages: fixtureSwitch })
let map = await router.resolvePageMap('/')

@@ -20,3 +20,3 @@ expect(Object.keys(map).length).toBe(4)

test("doesn't include content", async () => {
let router = createRouter({ rootSwitch: fixtureSwitch })
let router = createRouter({ pages: fixtureSwitch })
let map = await router.resolvePageMap('/')

@@ -27,3 +27,3 @@ expect(map['/'].content).toBeUndefined()

test("can map from an intermediate url and exclude its index", async () => {
let router = createRouter({ rootSwitch: fixtureSwitch })
let router = createRouter({ pages: fixtureSwitch })
let map = await router.resolvePageMap('/examples', {

@@ -38,3 +38,3 @@ predicate: (segment) => segment.url.pathname !== '/examples/'

test("follows redirects when { followRedirects: true }", async () => {
let router = createRouter({ rootSwitch: fixtureSwitch })
let router = createRouter({ pages: fixtureSwitch })
let route = await router.resolve('/examples', { followRedirects: true })

@@ -47,3 +47,3 @@ expect(route.url.pathname).toBe('/examples/basic/')

test("includes redirects", async () => {
let router = createRouter({ rootSwitch: fixtureSwitch })
let router = createRouter({ pages: fixtureSwitch })
let map = await router.resolveSiteMap('/')

@@ -50,0 +50,0 @@ expect(Object.keys(map.redirects).length).toBe(1)

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

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

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 too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc