@alwatr/router
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -6,6 +6,65 @@ # Change Log | ||
## [1.0.1](https://github.com/AliMD/alwatr/compare/v1.0.0...v1.0.1) (2023-06-21) | ||
# 1.1.0 (2023-09-12) | ||
**Note:** Version bump only for package @alwatr/router | ||
# 1.0.0 (2023-06-14) | ||
# 0.32.0 (2023-05-27) | ||
# 0.31.0 (2023-05-08) | ||
### Bug Fixes | ||
* new logger api ([9d83a7d](https://github.com/AliMD/alwatr/commit/9d83a7dc5c103bc3bb4282dacfd85fa998915300)) | ||
### Features | ||
* **router:** add thisArg for routerOutlet ([2bfd1f5](https://github.com/AliMD/alwatr/commit/2bfd1f5b8593f7107b4e84b35600cc07ca3d6c6c)) | ||
# 0.30.0 (2023-03-06) | ||
### Bug Fixes | ||
* **router:** home page for sub page routes ([af737f3](https://github.com/AliMD/alwatr/commit/af737f3451fd057f0a2a574be05c34bd06c0f7c0)) | ||
* **router:** make url from router respect empty sectionList ([1fb62f7](https://github.com/AliMD/alwatr/commit/1fb62f774bf5e9e6b68c04d756b32177697e55e8)) | ||
### Features | ||
* **router:** internal redirect render template to another route ([de92671](https://github.com/AliMD/alwatr/commit/de9267126935b73dd561d8817346410f00960234)) | ||
* **router:** keepSectionSlice for redirect ([1c3b370](https://github.com/AliMD/alwatr/commit/1c3b370c41f96a8ad612ea9fd5ab9963f6a3b27b)) | ||
# 0.29.0 (2023-02-10) | ||
### Bug Fixes | ||
* **route:** cleanup old api ([cf42205](https://github.com/AliMD/alwatr/commit/cf422055b96dbfd33a23732fe3e1def8b86e73c5)) | ||
* **route:** export types ([551f4e3](https://github.com/AliMD/alwatr/commit/551f4e3509cd7b50477c3eefc72a34145e710aa0)) | ||
* **router:** makeRouteContext as soon as posible ([f092b45](https://github.com/AliMD/alwatr/commit/f092b4584cc5fc424ac63cdf40b7c635053b9720)) | ||
* **route:** RouteContextBase type ([9e9ee78](https://github.com/AliMD/alwatr/commit/9e9ee7861bebfe68990171799537d3664ac1a66e)) | ||
* **router:** protocol type ([01fa523](https://github.com/AliMD/alwatr/commit/01fa52381d5ac9760c9af0d595826565548c6841)) | ||
### Features | ||
* **route:** makeRouteContext ([16be581](https://github.com/AliMD/alwatr/commit/16be5815a4a44f22bd17c4a87f1b7ef30f9aec6c)) | ||
* **route:** new url method ([580f2b3](https://github.com/AliMD/alwatr/commit/580f2b34396461389da0126d64c3c6ffde99e87b)) | ||
* **route:** redirect with update browser history ([d6d64a0](https://github.com/AliMD/alwatr/commit/d6d64a0fc80284e279db4515d95ff99f530b447f)) | ||
* **router:** enhance logging ([d5930ea](https://github.com/AliMD/alwatr/commit/d5930ea6117b4794c3771a8331c0d6ae063dd52e)) | ||
* **router:** export main api in index and auto init ([58718eb](https://github.com/AliMD/alwatr/commit/58718ebaa10c784255b4a0faa467d35659a1b1df)) | ||
* **router:** initialize process on DOMContentLoaded ([6b114e2](https://github.com/AliMD/alwatr/commit/6b114e2f64a50a40467bff20ecf562d1b7827632)) | ||
* **router:** new api from scratch! ([2b26a8d](https://github.com/AliMD/alwatr/commit/2b26a8d9f95b5968dbda003edc9d540ea95fadd1)) | ||
# 0.28.0 (2023-01-20) | ||
# 0.27.0 (2022-12-29) | ||
### Bug Fixes | ||
* **core/router:** preventDefault on svg link click ([e35e935](https://github.com/AliMD/alwatr/commit/e35e9351857d5bcb5128afbc87eb62dd11da865e)) | ||
# 0.26.0 (2022-12-22) | ||
### Bug Fixes | ||
* set correct path ([d01ce6f](https://github.com/AliMD/alwatr/commit/d01ce6ffa749a5e3e0e11e35b4ed61d75d61fec9)) | ||
* tsconfig ([e96dcd3](https://github.com/AliMD/alwatr/commit/e96dcd30774a9f06f7d051e0504192cbbe019e35)) | ||
# [1.0.0](https://github.com/AliMD/alwatr/compare/v0.32.0...v1.0.0) (2023-06-14) | ||
@@ -12,0 +71,0 @@ |
25
core.js
@@ -1,2 +0,1 @@ | ||
var _a; | ||
import { createLogger, globalAlwatr } from '@alwatr/logger'; | ||
@@ -12,3 +11,3 @@ import { isNumber } from '@alwatr/math'; | ||
export const routeContextProvider = contextProvider.bind('route-context'); | ||
const documentBaseUrl = ((_a = document.querySelector('base')) === null || _a === void 0 ? void 0 : _a.href) || '/'; | ||
const documentBaseUrl = document.querySelector('base')?.href || '/'; | ||
/** | ||
@@ -43,4 +42,3 @@ * The result of calling the current route's render() callback base on routesConfig. | ||
export const routerOutlet = (routesConfig, thisArg = null) => { | ||
var _a, _b, _c; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'routerOutlet', { routesConfig }); | ||
logger.logMethodArgs?.('routerOutlet', { routesConfig }); | ||
const routeContext = routeContextConsumer.getValue(); | ||
@@ -51,3 +49,3 @@ if (routeContext == null) { | ||
} | ||
const routeId = (_b = routesConfig.routeId(routeContext)) !== null && _b !== void 0 ? _b : ''; | ||
const routeId = routesConfig.routeId(routeContext) ?? ''; | ||
let render = routesConfig.templates[routeId]; | ||
@@ -66,3 +64,3 @@ while (typeof render === 'string') { | ||
// else | ||
(_c = logger.incident) === null || _c === void 0 ? void 0 : _c.call(logger, 'routerOutlet', 'page_not_found', 'Requested page not defined in routesConfig.templates', { | ||
logger.incident?.('routerOutlet', 'page_not_found', 'Requested page not defined in routesConfig.templates', { | ||
routeId, | ||
@@ -89,4 +87,3 @@ routeContext, | ||
export const url = (route) => { | ||
var _a; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'url', { route }); | ||
logger.logMethodArgs?.('url', { route }); | ||
let href = ''; | ||
@@ -119,6 +116,5 @@ if (Array.isArray(route.sectionList)) { | ||
export const redirect = (route, pushState = true, keepSectionSlice = 0) => { | ||
var _a; | ||
if (route == null) | ||
return; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'redirect', route); | ||
logger.logMethodArgs?.('redirect', route); | ||
if (keepSectionSlice > 0 && typeof route === 'object' && Array.isArray(route.sectionList)) { | ||
@@ -139,6 +135,5 @@ const routeContext = routeContextConsumer.getValue(); | ||
export const updateBrowserHistory = (url, pushState) => { | ||
var _a; | ||
if (pushState === false || globalThis.history == null) | ||
return; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'updateBrowserHistory', url); | ||
logger.logMethodArgs?.('updateBrowserHistory', url); | ||
if (location.href === url) | ||
@@ -157,4 +152,3 @@ return; | ||
export function makeRouteContext() { | ||
var _a; | ||
(_a = logger.logMethod) === null || _a === void 0 ? void 0 : _a.call(logger, 'makeRouteContext'); | ||
logger.logMethod?.('makeRouteContext'); | ||
const sectionList = location.pathname | ||
@@ -219,4 +213,3 @@ .split('/') | ||
export const parseQueryParamString = (queryParameter) => { | ||
var _a; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'parseQueryParamString', { queryParamString: queryParameter }); | ||
logger.logMethodArgs?.('parseQueryParamString', { queryParamString: queryParameter }); | ||
const queryParamList = {}; | ||
@@ -223,0 +216,0 @@ if (queryParameter == null) |
@@ -10,4 +10,3 @@ import { logger, makeRouteContext, routeContextProvider } from './core.js'; | ||
(() => { | ||
var _a, _b; | ||
(_a = logger.logMethod) === null || _a === void 0 ? void 0 : _a.call(logger, 'initialize'); | ||
logger.logMethod?.('initialize'); | ||
clickTrigger.enable = popstateTrigger.enable = true; | ||
@@ -18,5 +17,5 @@ if (routeContextProvider.getValue() === undefined) { | ||
else { | ||
(_b = logger.incident) === null || _b === void 0 ? void 0 : _b.call(logger, 'initialize', 'skip_route_context', 'Route context already have value'); | ||
logger.incident?.('initialize', 'skip_route_context', 'Route context already have value'); | ||
} | ||
})(); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@alwatr/router", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Elegant powerful router (fundamental advance browser page routing) based on the simplicity of the signals written in tiny TypeScript module.", | ||
@@ -34,11 +34,8 @@ "keywords": [ | ||
"dependencies": { | ||
"@alwatr/logger": "^1.0.1", | ||
"@alwatr/math": "^1.0.1", | ||
"@alwatr/signal": "^1.0.1", | ||
"tslib": "^2.5.3" | ||
"@alwatr/logger": "^1.1.0", | ||
"@alwatr/math": "^1.1.0", | ||
"@alwatr/signal": "^1.1.0", | ||
"tslib": "^2.6.2" | ||
}, | ||
"devDependencies": { | ||
"@alwatr/type": "^1.0.1" | ||
}, | ||
"gitHead": "10b9734389e27538ba4fa4ac7871ec0354ca9285" | ||
"gitHead": "e5c3bcb9d4f391a5a94d1469c5d31cbcd102c90b" | ||
} |
@@ -14,4 +14,3 @@ import { logger, redirect } from './core.js'; | ||
_clickHandler(event) { | ||
var _a, _b; | ||
(_a = logger.logMethod) === null || _a === void 0 ? void 0 : _a.call(logger, '_clickHandler'); | ||
logger.logMethod?.('_clickHandler'); | ||
if ( | ||
@@ -36,3 +35,3 @@ // ignore if the default action is prevented. | ||
.composedPath() | ||
.find((target) => { var _a; return ((_a = target === null || target === void 0 ? void 0 : target.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'a'; }); | ||
.find((target) => target?.tagName?.toLowerCase() === 'a'); | ||
if ( | ||
@@ -42,3 +41,3 @@ // ignore if the anchor is not found. | ||
// ignore if the anchor is not an <a> element. | ||
((_b = anchor.tagName) === null || _b === void 0 ? void 0 : _b.toLowerCase()) !== 'a' || | ||
anchor.tagName?.toLowerCase() !== 'a' || | ||
// ignore if the <a> element has a non-default target. | ||
@@ -71,4 +70,3 @@ (typeof anchor.target === 'string' && anchor.target !== '' && anchor.target.toLowerCase() !== '_self') || | ||
set enable(enable) { | ||
var _a; | ||
(_a = logger.logProperty) === null || _a === void 0 ? void 0 : _a.call(logger, 'clickTrigger.enable', enable); | ||
logger.logProperty?.('clickTrigger.enable', enable); | ||
if (enable && !_enabled) { | ||
@@ -75,0 +73,0 @@ window.document.addEventListener('click', clickTrigger._clickHandler); |
@@ -11,5 +11,4 @@ import { logger, redirect } from './core.js'; | ||
_popstateHandler(event) { | ||
var _a, _b; | ||
const href = (_a = globalThis.location) === null || _a === void 0 ? void 0 : _a.href; | ||
(_b = logger.logMethodArgs) === null || _b === void 0 ? void 0 : _b.call(logger, '_popstateHandler', href); | ||
const href = globalThis.location?.href; | ||
logger.logMethodArgs?.('_popstateHandler', href); | ||
if (event.state === 'router-ignore') | ||
@@ -20,4 +19,3 @@ return; | ||
set enable(enable) { | ||
var _a; | ||
(_a = logger.logProperty) === null || _a === void 0 ? void 0 : _a.call(logger, 'popstateTrigger.enable', enable); | ||
logger.logProperty?.('popstateTrigger.enable', enable); | ||
if (enable && !_enabled) { | ||
@@ -24,0 +22,0 @@ globalThis.addEventListener('popstate', popstateTrigger._popstateHandler); |
@@ -1,2 +0,2 @@ | ||
import type { QueryParameters } from '@alwatr/type'; | ||
import type { QueryParameters, StringifyableRecord } from '@alwatr/type'; | ||
/** | ||
@@ -16,7 +16,7 @@ * Route context base type. | ||
*/ | ||
export type RouteContextBase = { | ||
sectionList: Array<string | number | boolean>; | ||
export interface RouteContextBase extends StringifyableRecord { | ||
sectionList: (string | number | boolean)[]; | ||
queryParamList: QueryParameters; | ||
hash: string; | ||
}; | ||
} | ||
/** | ||
@@ -41,3 +41,3 @@ * Global route context type. | ||
*/ | ||
export type RouteContext = RouteContextBase & { | ||
export interface RouteContext extends RouteContextBase { | ||
href: string; | ||
@@ -49,3 +49,3 @@ pathname: string; | ||
protocol: 'HTTP' | 'HTTPS'; | ||
}; | ||
} | ||
export type PushState = boolean | 'replace'; | ||
@@ -79,7 +79,7 @@ /** | ||
*/ | ||
export type RouterTemplates = { | ||
export interface RouterTemplates { | ||
[x: string]: TemplateCallback | string | undefined; | ||
home: TemplateCallback; | ||
_404: TemplateCallback; | ||
}; | ||
} | ||
/** | ||
@@ -86,0 +86,0 @@ * Routes config for routerOutlet. |
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
70643
0
628
Updated@alwatr/logger@^1.1.0
Updated@alwatr/math@^1.1.0
Updated@alwatr/signal@^1.1.0
Updatedtslib@^2.6.2