Skip to content

Commit

Permalink
Release 7.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Masquerade-Circus committed Dec 17, 2022
1 parent 84770ef commit c23969b
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 38 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@


### [7.0.4](https://github.com/Masquerade-Circus/valyrian.js/compare/7.0.3...7.0.4) (2022-12-17)
## [7.1.0](https://github.com/Masquerade-Circus/valyrian.js/compare/7.0.4...7.1.0) (2022-12-17)


### Features

* **router:** add a way to initialize the router with a prefix ([84770ef](https://github.com/Masquerade-Circus/valyrian.js/commit/84770efac1ce0b2a3a43526b43ae9d0a6d5de78f))

### [7.0.4](https://github.com/Masquerade-Circus/valyrian.js/compare/7.0.3...7.0.4) (2022-12-17)

### Styles

* add comments to main and improve RouterInterface ([4e40a35](https://github.com/Masquerade-Circus/valyrian.js/commit/4e40a35ade8f4776f5c9218017d50a6f18d2e0b8))
* add comments to main and improve RouterInterface ([4e40a35](https://github.com/Masquerade-Circus/valyrian.js/commit/4e40a35ade8f4776f5c9218017d50a6f18d2e0b8))

### [7.0.3](https://github.com/Masquerade-Circus/valyrian.js/compare/7.0.2...7.0.3) (2022-10-24)

Expand Down
4 changes: 3 additions & 1 deletion dist/router/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ export declare class Router implements RouterInterface {
path: string;
params: Record<string, string | number | any>;
matches: string[];
pathPrefix: string;
constructor(pathPrefix?: string);
add(path: string, ...args: Middlewares): Router;
use(...args: Middlewares | Router[]): Router;
use(...args: Middlewares | Router[] | string[]): Router;
routes(): string[];
go(path: string, parentComponent?: Component): Promise<string | void>;
getOnClickHandler(url: string): (e: MouseEvent) => void;
Expand Down
2 changes: 1 addition & 1 deletion dist/router/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 19 additions & 15 deletions dist/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,27 +125,30 @@ var Router = class {
path = "";
params = {};
matches = [];
pathPrefix = "";
constructor(pathPrefix = "") {
this.pathPrefix = pathPrefix;
}
add(path, ...args) {
addPath(this, "add", path, args);
addPath(this, "add", `${this.pathPrefix}${path}`, args);
return this;
}
use(...args) {
let path = typeof args[0] === "string" ? args.shift() : "/";
let i;
let k;
let subrouter;
let path = `${this.pathPrefix}${typeof args[0] === "string" ? args.shift() : "/"}`;
let item;
let subpath;
for (i = 0; i < args.length; i++) {
subrouter = args[i];
if (typeof subrouter === "function") {
addPath(this, "use", `${path}.*`, [subrouter]);
} else if (subrouter.paths) {
for (k = 0; k < subrouter.paths.length; k++) {
for (let i = 0; i < args.length; i++) {
if (args[i] instanceof Router) {
let subrouter = args[i];
for (let k = 0; k < subrouter.paths.length; k++) {
item = subrouter.paths[k];
subpath = `${path}${item.path}`.replace(/^\/\//, "/");
addPath(this, item.method, subpath, item.middlewares);
}
continue;
}
if (typeof args[i] === "function") {
addPath(this, "use", `${path}.*`, [args[i]]);
}
}
return this;
Expand All @@ -163,18 +166,19 @@ var Router = class {
if (!path) {
throw new Error("router.url.required");
}
let parts = path.split("?", 2);
let constructedPath = `${this.pathPrefix}${path}`;
let parts = constructedPath.split("?", 2);
let urlParts = parts[0].replace(/(.+)\/$/, "$1");
let queryParts = parts[1];
this.url = path;
this.url = constructedPath;
this.query = parseQuery(queryParts);
let middlewares = searchMiddlewares(this, urlParts);
let component = await searchComponent(this, middlewares);
if (component === false) {
return;
}
if (!component) {
throw new Error(`The url ${path} requested wasn't found`);
throw new Error(`The url ${constructedPath} requested wasn't found`);
}
if ((0, import_valyrian.isComponent)(parentComponent) || (0, import_valyrian.isVnodeComponent)(parentComponent)) {
let childComponent = (0, import_valyrian.isVnodeComponent)(component) ? component : (0, import_valyrian.v)(component, {});
Expand All @@ -186,7 +190,7 @@ var Router = class {
}
}
if (!import_valyrian.isNodeJs) {
window.history.pushState(null, "", path);
window.history.pushState(null, "", constructedPath);
}
if (this.container) {
return (0, import_valyrian.mount)(this.container, component);
Expand Down
34 changes: 19 additions & 15 deletions dist/router/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -108,27 +108,30 @@ var Router = class {
path = "";
params = {};
matches = [];
pathPrefix = "";
constructor(pathPrefix = "") {
this.pathPrefix = pathPrefix;
}
add(path, ...args) {
addPath(this, "add", path, args);
addPath(this, "add", `${this.pathPrefix}${path}`, args);
return this;
}
use(...args) {
let path = typeof args[0] === "string" ? args.shift() : "/";
let i;
let k;
let subrouter;
let path = `${this.pathPrefix}${typeof args[0] === "string" ? args.shift() : "/"}`;
let item;
let subpath;
for (i = 0; i < args.length; i++) {
subrouter = args[i];
if (typeof subrouter === "function") {
addPath(this, "use", `${path}.*`, [subrouter]);
} else if (subrouter.paths) {
for (k = 0; k < subrouter.paths.length; k++) {
for (let i = 0; i < args.length; i++) {
if (args[i] instanceof Router) {
let subrouter = args[i];
for (let k = 0; k < subrouter.paths.length; k++) {
item = subrouter.paths[k];
subpath = `${path}${item.path}`.replace(/^\/\//, "/");
addPath(this, item.method, subpath, item.middlewares);
}
continue;
}
if (typeof args[i] === "function") {
addPath(this, "use", `${path}.*`, [args[i]]);
}
}
return this;
Expand All @@ -146,18 +149,19 @@ var Router = class {
if (!path) {
throw new Error("router.url.required");
}
let parts = path.split("?", 2);
let constructedPath = `${this.pathPrefix}${path}`;
let parts = constructedPath.split("?", 2);
let urlParts = parts[0].replace(/(.+)\/$/, "$1");
let queryParts = parts[1];
this.url = path;
this.url = constructedPath;
this.query = parseQuery(queryParts);
let middlewares = searchMiddlewares(this, urlParts);
let component = await searchComponent(this, middlewares);
if (component === false) {
return;
}
if (!component) {
throw new Error(`The url ${path} requested wasn't found`);
throw new Error(`The url ${constructedPath} requested wasn't found`);
}
if (isComponent(parentComponent) || isVnodeComponent(parentComponent)) {
let childComponent = isVnodeComponent(component) ? component : v(component, {});
Expand All @@ -169,7 +173,7 @@ var Router = class {
}
}
if (!isNodeJs) {
window.history.pushState(null, "", path);
window.history.pushState(null, "", constructedPath);
}
if (this.container) {
return mount(this.container, component);
Expand Down
2 changes: 1 addition & 1 deletion lib/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class Router implements RouterInterface {
matches: string[] = [];
pathPrefix: string = "";

constructor(pathPrefix: string) {
constructor(pathPrefix: string = "") {
this.pathPrefix = pathPrefix;
}

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "valyrian.js",
"version": "7.0.4",
"version": "7.1.0",
"description": "Lightweight steel to forge PWAs. (Minimal Frontend Framework with server side rendering and other capabilities)",
"repository": "git@github.com:Masquerade-Circus/valyrian.js.git",
"author": "Masquerade <christian@masquerade-circus.net>",
Expand Down

0 comments on commit c23969b

Please sign in to comment.