vaderjs 1.2.4 → 1.2.6

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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/vader.js +21 -8
  3. package/vaderRouter.js +21 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vaderjs",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
4
4
  "description": "A Reactive Framework for Single-Page Applications (SPA)",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/vader.js CHANGED
@@ -181,8 +181,18 @@ export class Component {
181
181
  },
182
182
  });
183
183
  this.snapshots = [];
184
+
184
185
  }
185
186
 
187
+ /**
188
+ * @method adapter
189
+ * @description Allows you to create an adapter - this is used to create custom logic
190
+ *
191
+ *
192
+ */
193
+ adapter() {
194
+ return
195
+ }
186
196
  init() {
187
197
  this.registerComponent();
188
198
  }
@@ -860,8 +870,10 @@ export class Component {
860
870
  throw new SyntaxError(
861
871
  `Image: ${element.outerHTML} alt attribute cannot be empty`
862
872
  );
873
+
863
874
  } else if (
864
875
  element.hasAttribute("src") &&
876
+ !element.getAttribute("src")?.includes("http") || !element.getAttribute("src")?.includes("https") &&
865
877
  !document.documentElement.outerHTML
866
878
  .trim()
867
879
  .includes("<!-- #vader-disable_accessibility -->")
@@ -955,16 +967,17 @@ export class Component {
955
967
  }
956
968
 
957
969
  if (
958
- element.hasAttribute("src") &&
959
- // @ts-ignore
960
- element.getAttribute("src").startsWith("/") &&
961
- !document.documentElement.outerHTML
962
- .trim()
963
- .includes("<!-- #vader-disable_relative-paths -->")
970
+ element.hasAttribute("src") &&
971
+ // @ts-ignore
972
+ !element.getAttribute("src").includes("http") &&
973
+ // @ts-ignore
974
+ !element.getAttribute("src").includes("https") &&
975
+ !document.documentElement.outerHTML.includes(`<!-- #vader-disable_relative-paths -->`)
964
976
  ) {
965
977
  element.setAttribute(
966
978
  "src",
967
- `${window.location.origin}/public${element.getAttribute("src")}`
979
+ // @ts-ignore
980
+ `./public/${element.getAttribute("src")}`
968
981
  );
969
982
  }
970
983
  break;
@@ -1124,4 +1137,4 @@ export const include = async (path) => {
1124
1137
  });
1125
1138
  };
1126
1139
 
1127
- export default Vader
1140
+ export default Vader;
package/vaderRouter.js CHANGED
@@ -2,6 +2,7 @@
2
2
  /**
3
3
  * @class VaderRouter
4
4
  * @description - creates an instance of Vader Express Router
5
+ *
5
6
  * @param {String} path
6
7
  * @param {Function} handler
7
8
  * @param {object} req request object
@@ -10,11 +11,18 @@
10
11
  *
11
12
  */
12
13
  class VaderRouter{
13
- constructor() {
14
+ /**
15
+ * @constructor
16
+ * @param {*} basePath
17
+ *
18
+ */
19
+ constructor(basePath) {
14
20
  this.routes = [];
15
21
  this.middlewares = [];
16
22
  this.errorMiddlewares = [];
17
23
  this.listeners = [];
24
+
25
+ this.basePath = basePath;
18
26
  }
19
27
 
20
28
  /**
@@ -124,22 +132,27 @@ class VaderRouter{
124
132
  }
125
133
  const routePathParts = route.path.split('/');
126
134
  const hashParts = hash.split('/');
127
- // if asterisk is present in route path then it will be the last part
128
- if(routePathParts[routePathParts.length-1].startsWith('*')){
129
- return true;
130
- }else if (routePathParts.length !== hashParts.length) {
135
+ if (routePathParts.length !== hashParts.length) {
131
136
  return false;
137
+ }else if(routePathParts[routePathParts.length-1].startsWith('*')){
138
+ return true;
132
139
  }
133
-
134
140
  const params = this.extractParams( route.path, hash);
135
141
  return Object.keys(params).length > 0;
136
142
  });
137
143
 
138
144
  if (!route) {
139
145
  route = this.routes.find((route) => {
140
- return route.path === '/404';
146
+
147
+ if(route.path === '/404'){
148
+ return true;
149
+ }else{
150
+ window.location.hash = this.basePath
151
+ }
141
152
  });
142
153
 
154
+ route ? status = 200 :
155
+
143
156
  status = 404;
144
157
  }
145
158
 
@@ -213,6 +226,4 @@ class VaderRouter{
213
226
 
214
227
  }
215
228
 
216
- export default VaderRouter;
217
-
218
-
229
+ export default VaderRouter;