htmx-router 0.0.6 → 0.0.7

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.
@@ -23,11 +23,11 @@ export declare class RenderArgs {
23
23
  _maskChain: MaskType[];
24
24
  _maxChain: number;
25
25
  constructor(req: http.IncomingMessage, res: http.ServerResponse, url: URL);
26
- addLinks(links: MetaHTML[], override?: boolean): void;
27
- addMeta(links: MetaHTML[], override?: boolean): void;
26
+ addLinks: (links: MetaHTML[], override?: boolean) => void;
27
+ addMeta: (links: MetaHTML[], override?: boolean) => void;
28
28
  Outlet: () => Promise<string>;
29
29
  _addOutlet(route: RouteLeaf): void;
30
30
  _applyMask(mask: boolean[], depth: number): void;
31
- renderHeadHTML(): string;
31
+ renderHeadHTML: () => string;
32
32
  }
33
33
  export {};
@@ -24,6 +24,26 @@ var MaskType;
24
24
  })(MaskType || (exports.MaskType = MaskType = {}));
25
25
  class RenderArgs {
26
26
  constructor(req, res, url) {
27
+ this.addLinks = (links, override = false) => {
28
+ if (!ValidateMetaHTMLs(links))
29
+ throw new Error(`Provided links have invalid attribute`);
30
+ if (override) {
31
+ this.links = links;
32
+ }
33
+ else {
34
+ this.links.push(...links);
35
+ }
36
+ };
37
+ this.addMeta = (links, override = false) => {
38
+ if (!ValidateMetaHTMLs(links))
39
+ throw new Error(`Provided links have invalid attribute`);
40
+ if (override) {
41
+ this.meta = links;
42
+ }
43
+ else {
44
+ this.meta.push(...links);
45
+ }
46
+ };
27
47
  // unpacking Outlet caused this to be undefined
28
48
  // hence the weird def
29
49
  this.Outlet = () => {
@@ -38,6 +58,24 @@ class RenderArgs {
38
58
  const routeName = `hx-route-${depth.toString(16)}`;
39
59
  return route.render(this, mask, routeName);
40
60
  };
61
+ this.renderHeadHTML = () => {
62
+ let out = "";
63
+ for (const elm of this.links) {
64
+ out += "<link";
65
+ for (const attr in elm) {
66
+ out += ` ${attr}="${elm[attr].replace(/"/g, "\\\"")}"`;
67
+ }
68
+ out += "></link>";
69
+ }
70
+ for (const elm of this.meta) {
71
+ out += "<meta";
72
+ for (const attr in elm) {
73
+ out += ` ${attr}="${elm[attr].replace(/"/g, "\\\"")}"`;
74
+ }
75
+ out += "></meta>";
76
+ }
77
+ return out;
78
+ };
41
79
  this.req = req;
42
80
  this.res = res;
43
81
  this.url = url;
@@ -49,32 +87,14 @@ class RenderArgs {
49
87
  this._maskChain = [];
50
88
  this._maxChain = 0;
51
89
  }
52
- addLinks(links, override = false) {
53
- if (!ValidateMetaHTMLs(links))
54
- throw new Error(`Provided links have invalid attribute`);
55
- if (override) {
56
- this.links = links;
57
- }
58
- else {
59
- this.links.push(...links);
60
- }
61
- }
62
- addMeta(links, override = false) {
63
- if (!ValidateMetaHTMLs(links))
64
- throw new Error(`Provided links have invalid attribute`);
65
- if (override) {
66
- this.meta = links;
67
- }
68
- else {
69
- this.meta.push(...links);
70
- }
71
- }
72
90
  _addOutlet(route) {
73
91
  this._outletChain.push(route);
74
92
  }
75
93
  _applyMask(mask, depth) {
76
94
  const padded = new Array(this._outletChain.length - mask.length).fill(false);
77
- padded.push(...mask);
95
+ for (let i = mask.length - 1; i >= 0; i--) {
96
+ padded.push(mask[i]);
97
+ }
78
98
  this._maskChain = padded
79
99
  .map((x, i) => x === true ?
80
100
  MaskType.hide :
@@ -83,23 +103,5 @@ class RenderArgs {
83
103
  MaskType.headless);
84
104
  this._maxChain = this._maskChain.length;
85
105
  }
86
- renderHeadHTML() {
87
- let out = "";
88
- for (const elm of this.links) {
89
- out += "<link";
90
- for (const attr in elm) {
91
- out += ` ${attr}="${elm[attr].replace(/"/g, "\\\"")}"`;
92
- }
93
- out += "></link>";
94
- }
95
- for (const elm of this.meta) {
96
- out += "<meta";
97
- for (const attr in elm) {
98
- out += ` ${attr}="${elm[attr].replace(/"/g, "\\\"")}"`;
99
- }
100
- out += "></meta>";
101
- }
102
- return out;
103
- }
104
106
  }
105
107
  exports.RenderArgs = RenderArgs;
package/bin/router.js CHANGED
@@ -95,10 +95,12 @@ class RouteTree {
95
95
  path = path.split(/[\./\\]/g);
96
96
  }
97
97
  if (path.length === 0) {
98
+ override.push(false);
98
99
  this.route = new RouteLeaf(module, override);
99
100
  return;
100
101
  }
101
102
  if (path.length === 1 && path[0] === "_index") {
103
+ override.push(false);
102
104
  this.default = new RouteLeaf(module, override);
103
105
  return;
104
106
  }
@@ -255,7 +257,7 @@ function BuildOutlet(start, args, fromPath) {
255
257
  }
256
258
  }
257
259
  if (matching) {
258
- depth = args._outletChain.length;
260
+ depth = args._outletChain.length - 1;
259
261
  }
260
262
  args._applyMask(mask, depth);
261
263
  return depth;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "htmx-router",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "A remix.js style file path router for htmX websites",
5
5
  "main": "./bin/index.js",
6
6
  "scripts": {