valyrian.js 7.0.4 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -42,8 +42,10 @@ export declare class Router implements RouterInterface {
42
42
  path: string;
43
43
  params: Record<string, string | number | any>;
44
44
  matches: string[];
45
+ pathPrefix: string;
46
+ constructor(pathPrefix?: string);
45
47
  add(path: string, ...args: Middlewares): Router;
46
- use(...args: Middlewares | Router[]): Router;
48
+ use(...args: Middlewares | Router[] | string[]): Router;
47
49
  routes(): string[];
48
50
  go(path: string, parentComponent?: Component): Promise<string | void>;
49
51
  getOnClickHandler(url: string): (e: MouseEvent) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/router/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,aAAa,EACb,uBAAuB,EAQxB,MAAM,aAAa,CAAC;AAErB,UAAU,IAAI;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,WAAW,CAAC;IACzB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,OAAO;IACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,EAAE,CAAC;IAElB,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,SAAS,GAAG,aAAa,GAAG,uBAAuB,KAAK,KAAK,CAAC;CAC1G;AAED,UAAU,UAAU;IAElB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,GAAG,GACpB,OAAO,CAAC,GAAG,GAAG,SAAS,GAAG,aA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AAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAM;IAC5C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAM;IAClC,GAAG,EAAE,MAAM,CAAM;IACjB,IAAI,EAAE,MAAM,CAAM;IAClB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC,CAAM;IACnD,OAAO,EAAE,MAAM,EAAE,CAAM;IACvB,UAAU,EAAE,MAAM,CAAM;gBAEZ,UAAU,GAAE,MAAW;IAInC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,WAAW,GAAG,MAAM;IAK/C,GAAG,CAAC,GAAG,IAAI,EAAE,WAAW,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,MAAM;IAwBvD,MAAM;IAUA,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IA2C3E,iBAAiB,CAAC,GAAG,EAAE,MAAM,OAChB,UAAU;CAOxB;AAGD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,OAKnC;AAED,wBAAgB,WAAW,CAAC,gBAAgB,KAAA,EAAE,MAAM,KAAA,QAiBnD"}
@@ -125,27 +125,30 @@ var Router = class {
125
125
  path = "";
126
126
  params = {};
127
127
  matches = [];
128
+ pathPrefix = "";
129
+ constructor(pathPrefix = "") {
130
+ this.pathPrefix = pathPrefix;
131
+ }
128
132
  add(path, ...args) {
129
- addPath(this, "add", path, args);
133
+ addPath(this, "add", `${this.pathPrefix}${path}`, args);
130
134
  return this;
131
135
  }
132
136
  use(...args) {
133
- let path = typeof args[0] === "string" ? args.shift() : "/";
134
- let i;
135
- let k;
136
- let subrouter;
137
+ let path = `${this.pathPrefix}${typeof args[0] === "string" ? args.shift() : "/"}`;
137
138
  let item;
138
139
  let subpath;
139
- for (i = 0; i < args.length; i++) {
140
- subrouter = args[i];
141
- if (typeof subrouter === "function") {
142
- addPath(this, "use", `${path}.*`, [subrouter]);
143
- } else if (subrouter.paths) {
144
- for (k = 0; k < subrouter.paths.length; k++) {
140
+ for (let i = 0; i < args.length; i++) {
141
+ if (args[i] instanceof Router) {
142
+ let subrouter = args[i];
143
+ for (let k = 0; k < subrouter.paths.length; k++) {
145
144
  item = subrouter.paths[k];
146
145
  subpath = `${path}${item.path}`.replace(/^\/\//, "/");
147
146
  addPath(this, item.method, subpath, item.middlewares);
148
147
  }
148
+ continue;
149
+ }
150
+ if (typeof args[i] === "function") {
151
+ addPath(this, "use", `${path}.*`, [args[i]]);
149
152
  }
150
153
  }
151
154
  return this;
@@ -163,10 +166,11 @@ var Router = class {
163
166
  if (!path) {
164
167
  throw new Error("router.url.required");
165
168
  }
166
- let parts = path.split("?", 2);
169
+ let constructedPath = `${this.pathPrefix}${path}`;
170
+ let parts = constructedPath.split("?", 2);
167
171
  let urlParts = parts[0].replace(/(.+)\/$/, "$1");
168
172
  let queryParts = parts[1];
169
- this.url = path;
173
+ this.url = constructedPath;
170
174
  this.query = parseQuery(queryParts);
171
175
  let middlewares = searchMiddlewares(this, urlParts);
172
176
  let component = await searchComponent(this, middlewares);
@@ -174,7 +178,7 @@ var Router = class {
174
178
  return;
175
179
  }
176
180
  if (!component) {
177
- throw new Error(`The url ${path} requested wasn't found`);
181
+ throw new Error(`The url ${constructedPath} requested wasn't found`);
178
182
  }
179
183
  if ((0, import_valyrian.isComponent)(parentComponent) || (0, import_valyrian.isVnodeComponent)(parentComponent)) {
180
184
  let childComponent = (0, import_valyrian.isVnodeComponent)(component) ? component : (0, import_valyrian.v)(component, {});
@@ -186,7 +190,7 @@ var Router = class {
186
190
  }
187
191
  }
188
192
  if (!import_valyrian.isNodeJs) {
189
- window.history.pushState(null, "", path);
193
+ window.history.pushState(null, "", constructedPath);
190
194
  }
191
195
  if (this.container) {
192
196
  return (0, import_valyrian.mount)(this.container, component);
@@ -108,27 +108,30 @@ var Router = class {
108
108
  path = "";
109
109
  params = {};
110
110
  matches = [];
111
+ pathPrefix = "";
112
+ constructor(pathPrefix = "") {
113
+ this.pathPrefix = pathPrefix;
114
+ }
111
115
  add(path, ...args) {
112
- addPath(this, "add", path, args);
116
+ addPath(this, "add", `${this.pathPrefix}${path}`, args);
113
117
  return this;
114
118
  }
115
119
  use(...args) {
116
- let path = typeof args[0] === "string" ? args.shift() : "/";
117
- let i;
118
- let k;
119
- let subrouter;
120
+ let path = `${this.pathPrefix}${typeof args[0] === "string" ? args.shift() : "/"}`;
120
121
  let item;
121
122
  let subpath;
122
- for (i = 0; i < args.length; i++) {
123
- subrouter = args[i];
124
- if (typeof subrouter === "function") {
125
- addPath(this, "use", `${path}.*`, [subrouter]);
126
- } else if (subrouter.paths) {
127
- for (k = 0; k < subrouter.paths.length; k++) {
123
+ for (let i = 0; i < args.length; i++) {
124
+ if (args[i] instanceof Router) {
125
+ let subrouter = args[i];
126
+ for (let k = 0; k < subrouter.paths.length; k++) {
128
127
  item = subrouter.paths[k];
129
128
  subpath = `${path}${item.path}`.replace(/^\/\//, "/");
130
129
  addPath(this, item.method, subpath, item.middlewares);
131
130
  }
131
+ continue;
132
+ }
133
+ if (typeof args[i] === "function") {
134
+ addPath(this, "use", `${path}.*`, [args[i]]);
132
135
  }
133
136
  }
134
137
  return this;
@@ -146,10 +149,11 @@ var Router = class {
146
149
  if (!path) {
147
150
  throw new Error("router.url.required");
148
151
  }
149
- let parts = path.split("?", 2);
152
+ let constructedPath = `${this.pathPrefix}${path}`;
153
+ let parts = constructedPath.split("?", 2);
150
154
  let urlParts = parts[0].replace(/(.+)\/$/, "$1");
151
155
  let queryParts = parts[1];
152
- this.url = path;
156
+ this.url = constructedPath;
153
157
  this.query = parseQuery(queryParts);
154
158
  let middlewares = searchMiddlewares(this, urlParts);
155
159
  let component = await searchComponent(this, middlewares);
@@ -157,7 +161,7 @@ var Router = class {
157
161
  return;
158
162
  }
159
163
  if (!component) {
160
- throw new Error(`The url ${path} requested wasn't found`);
164
+ throw new Error(`The url ${constructedPath} requested wasn't found`);
161
165
  }
162
166
  if (isComponent(parentComponent) || isVnodeComponent(parentComponent)) {
163
167
  let childComponent = isVnodeComponent(component) ? component : v(component, {});
@@ -169,7 +173,7 @@ var Router = class {
169
173
  }
170
174
  }
171
175
  if (!isNodeJs) {
172
- window.history.pushState(null, "", path);
176
+ window.history.pushState(null, "", constructedPath);
173
177
  }
174
178
  if (this.container) {
175
179
  return mount(this.container, component);
@@ -191,30 +191,35 @@ export class Router implements RouterInterface {
191
191
  path: string = "";
192
192
  params: Record<string, string | number | any> = {};
193
193
  matches: string[] = [];
194
+ pathPrefix: string = "";
195
+
196
+ constructor(pathPrefix: string = "") {
197
+ this.pathPrefix = pathPrefix;
198
+ }
194
199
 
195
200
  add(path: string, ...args: Middlewares): Router {
196
- addPath(this, "add", path, args);
201
+ addPath(this, "add", `${this.pathPrefix}${path}`, args);
197
202
  return this;
198
203
  }
199
204
 
200
- use(...args: Middlewares | Router[]): Router {
201
- let path = typeof args[0] === "string" ? args.shift() : "/";
202
- let i;
203
- let k;
204
- let subrouter;
205
+ use(...args: Middlewares | Router[] | string[]): Router {
206
+ let path = `${this.pathPrefix}${typeof args[0] === "string" ? args.shift() : "/"}`;
205
207
  let item;
206
208
  let subpath;
207
209
 
208
- for (i = 0; i < args.length; i++) {
209
- subrouter = args[i];
210
- if (typeof subrouter === "function") {
211
- addPath(this, "use", `${path}.*`, [subrouter]);
212
- } else if (subrouter.paths) {
213
- for (k = 0; k < subrouter.paths.length; k++) {
210
+ for (let i = 0; i < args.length; i++) {
211
+ if (args[i] instanceof Router) {
212
+ let subrouter = args[i] as Router;
213
+ for (let k = 0; k < subrouter.paths.length; k++) {
214
214
  item = subrouter.paths[k];
215
215
  subpath = `${path}${item.path}`.replace(/^\/\//, "/");
216
216
  addPath(this, item.method, subpath, item.middlewares);
217
217
  }
218
+ continue;
219
+ }
220
+
221
+ if (typeof args[i] === "function") {
222
+ addPath(this, "use", `${path}.*`, [args[i]]);
218
223
  }
219
224
  }
220
225
 
@@ -236,10 +241,11 @@ export class Router implements RouterInterface {
236
241
  throw new Error("router.url.required");
237
242
  }
238
243
 
239
- let parts = path.split("?", 2);
244
+ let constructedPath = `${this.pathPrefix}${path}`;
245
+ let parts = constructedPath.split("?", 2);
240
246
  let urlParts = parts[0].replace(/(.+)\/$/, "$1");
241
247
  let queryParts = parts[1];
242
- this.url = path;
248
+ this.url = constructedPath;
243
249
  this.query = parseQuery(queryParts);
244
250
 
245
251
  let middlewares = searchMiddlewares(this as RouterInterface, urlParts);
@@ -251,7 +257,7 @@ export class Router implements RouterInterface {
251
257
  }
252
258
 
253
259
  if (!component) {
254
- throw new Error(`The url ${path} requested wasn't found`);
260
+ throw new Error(`The url ${constructedPath} requested wasn't found`);
255
261
  }
256
262
 
257
263
  if (isComponent(parentComponent) || isVnodeComponent(parentComponent)) {
@@ -265,7 +271,7 @@ export class Router implements RouterInterface {
265
271
  }
266
272
 
267
273
  if (!isNodeJs) {
268
- window.history.pushState(null, "", path);
274
+ window.history.pushState(null, "", constructedPath);
269
275
  }
270
276
 
271
277
  if (this.container) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "valyrian.js",
3
- "version": "7.0.4",
3
+ "version": "7.1.0",
4
4
  "description": "Lightweight steel to forge PWAs. (Minimal Frontend Framework with server side rendering and other capabilities)",
5
5
  "repository": "git@github.com:Masquerade-Circus/valyrian.js.git",
6
6
  "author": "Masquerade <christian@masquerade-circus.net>",