vaderjs 1.0.2 → 1.0.4
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.
- package/jsconfig.json +9 -4
- package/package.json +1 -1
- package/vader.js +57 -10
- package/vaderRouter.js +11 -3
- package/components/header.html +0 -20
- package/config.json +0 -7
package/jsconfig.json
CHANGED
|
@@ -2,8 +2,13 @@
|
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"allowJs": true,
|
|
4
4
|
"checkJs": true,
|
|
5
|
-
|
|
5
|
+
"jsx": "react",
|
|
6
|
+
"module": "esnext",
|
|
7
|
+
"moduleResolution": "node",
|
|
8
|
+
"noEmit": true,
|
|
9
|
+
"strict": true, // Enforce strict type checking
|
|
10
|
+
"forceConsistentCasingInFileNames": true, // Ensures consistent file name casing
|
|
11
|
+
"noImplicitAny": true,
|
|
6
12
|
},
|
|
7
|
-
"include": ["/"]
|
|
8
|
-
|
|
9
|
-
}
|
|
13
|
+
"include": ["/"]
|
|
14
|
+
}
|
package/package.json
CHANGED
package/vader.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Object window
|
|
3
|
+
* @property {Object} props
|
|
4
|
+
* @description Allows you to store props for component
|
|
5
|
+
*/
|
|
6
|
+
window.props = {}
|
|
1
7
|
/**
|
|
2
8
|
* @function vhtml
|
|
3
|
-
* @param {
|
|
9
|
+
* @param {String} strings
|
|
4
10
|
* @param {...any} args
|
|
5
11
|
* @returns modified string
|
|
6
12
|
*
|
|
7
13
|
*/
|
|
8
|
-
window.props = {}
|
|
9
14
|
export function vhtml(strings, ...args) {
|
|
10
15
|
let result = "";
|
|
11
16
|
|
|
@@ -97,6 +102,12 @@ export function component(name, options) {
|
|
|
97
102
|
window.props[key] = initialValue;
|
|
98
103
|
}
|
|
99
104
|
|
|
105
|
+
/**
|
|
106
|
+
* @Array state
|
|
107
|
+
* @param {*} states
|
|
108
|
+
* @description Allows you to get state of component
|
|
109
|
+
*/
|
|
110
|
+
|
|
100
111
|
return [states[key], (newValue) => setState(key, newValue)];
|
|
101
112
|
};
|
|
102
113
|
/**
|
|
@@ -118,11 +129,11 @@ export function component(name, options) {
|
|
|
118
129
|
};
|
|
119
130
|
|
|
120
131
|
/**
|
|
121
|
-
* @function
|
|
122
|
-
* @param {*}
|
|
123
|
-
* @param {*}
|
|
124
|
-
* @returns {Object} {
|
|
125
|
-
* @description Allows you to manage
|
|
132
|
+
* @function useSyncStore
|
|
133
|
+
* @param {*} storeName
|
|
134
|
+
* @param {*} initialState
|
|
135
|
+
* @returns {Object} {getField, setField, subscribe, clear}
|
|
136
|
+
* @description Allows you to manage state in local storage
|
|
126
137
|
*/
|
|
127
138
|
const useSyncStore = (storeName, initialState) => {
|
|
128
139
|
const storedState =
|
|
@@ -174,6 +185,14 @@ export function component(name, options) {
|
|
|
174
185
|
clear,
|
|
175
186
|
};
|
|
176
187
|
};
|
|
188
|
+
/**
|
|
189
|
+
* @function useAuth
|
|
190
|
+
* @param {*} rulesets
|
|
191
|
+
* @param {*} options
|
|
192
|
+
* @returns {Object} {canAccess, grantAccess, revokeAccess}
|
|
193
|
+
* @description Allows you to manage access to resources through rulesets
|
|
194
|
+
* @returns
|
|
195
|
+
*/
|
|
177
196
|
|
|
178
197
|
function useAuth(options) {
|
|
179
198
|
if (!options.rulesets) {
|
|
@@ -291,6 +310,7 @@ export function component(name, options) {
|
|
|
291
310
|
window.useEffect = useEffect;
|
|
292
311
|
window.useAuth = useAuth;
|
|
293
312
|
window.useSyncStore = useSyncStore;
|
|
313
|
+
|
|
294
314
|
const updateComponent = () => {
|
|
295
315
|
const componentContainer = document.querySelector(
|
|
296
316
|
`[data-component="${name}"]`
|
|
@@ -304,8 +324,16 @@ export function component(name, options) {
|
|
|
304
324
|
);
|
|
305
325
|
}
|
|
306
326
|
};
|
|
327
|
+
/**
|
|
328
|
+
* @function render
|
|
329
|
+
* @param {*} states
|
|
330
|
+
* @param {*} props
|
|
331
|
+
* @description Allows you to render component to DOM
|
|
332
|
+
* @returns {HTMLcContent}
|
|
333
|
+
* @returns
|
|
334
|
+
*/
|
|
307
335
|
|
|
308
|
-
const render = (props) => {
|
|
336
|
+
const render = async (props) => {
|
|
309
337
|
storedProps = props;
|
|
310
338
|
const componentContainer = document.querySelector(
|
|
311
339
|
`[data-component="${name}"]`
|
|
@@ -313,14 +341,14 @@ export function component(name, options) {
|
|
|
313
341
|
if (componentContainer) {
|
|
314
342
|
runEffects();
|
|
315
343
|
|
|
316
|
-
componentContainer.innerHTML = options.render(
|
|
344
|
+
componentContainer.innerHTML = await options.render(
|
|
317
345
|
states,
|
|
318
346
|
(storedProps = null)
|
|
319
347
|
);
|
|
320
348
|
} else {
|
|
321
349
|
return vhtml`
|
|
322
350
|
<div data-component="${name}">
|
|
323
|
-
${options.render(
|
|
351
|
+
${await options.render(
|
|
324
352
|
states,
|
|
325
353
|
props
|
|
326
354
|
)}
|
|
@@ -344,3 +372,22 @@ export function component(name, options) {
|
|
|
344
372
|
export const rf = (name, fn) => {
|
|
345
373
|
window[name] = fn;
|
|
346
374
|
};
|
|
375
|
+
/**
|
|
376
|
+
* @function include
|
|
377
|
+
* @description Allows you to include html file
|
|
378
|
+
* @returns - modified string with html content
|
|
379
|
+
* @param {string} path
|
|
380
|
+
*/
|
|
381
|
+
|
|
382
|
+
export const include = (path) => {
|
|
383
|
+
return fetch(`./${path}`)
|
|
384
|
+
.then((res) => {
|
|
385
|
+
if(res.status === 404){
|
|
386
|
+
throw new Error(`No file found at ${path}`)
|
|
387
|
+
}
|
|
388
|
+
return res.text()
|
|
389
|
+
})
|
|
390
|
+
.then((data) => {
|
|
391
|
+
return new Function(`return \`${data}\`;`)()
|
|
392
|
+
})
|
|
393
|
+
};
|
package/vaderRouter.js
CHANGED
|
@@ -81,7 +81,15 @@ class VaderRouter {
|
|
|
81
81
|
status: 404,
|
|
82
82
|
message: "Page not found",
|
|
83
83
|
};
|
|
84
|
-
|
|
84
|
+
const res = {
|
|
85
|
+
return: function (data) {
|
|
86
|
+
this.hooked = false;
|
|
87
|
+
},
|
|
88
|
+
render: function (selector, data) {
|
|
89
|
+
document.querySelector(selector).innerHTML = data;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
this.handleError("404", errBody, res);
|
|
85
93
|
}
|
|
86
94
|
});
|
|
87
95
|
}
|
|
@@ -111,9 +119,9 @@ class VaderRouter {
|
|
|
111
119
|
* @description used by start() to handle errors.
|
|
112
120
|
*/
|
|
113
121
|
|
|
114
|
-
handleError(type, data) {
|
|
122
|
+
handleError(type, data, res) {
|
|
115
123
|
if (this.errorHandlers[type]) {
|
|
116
|
-
this.errorHandlers[type](data);
|
|
124
|
+
this.errorHandlers[type](data, res);
|
|
117
125
|
} else {
|
|
118
126
|
console.error(`No error handler found for type: ${type}`);
|
|
119
127
|
}
|
package/components/header.html
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
<header>
|
|
2
|
-
<div>
|
|
3
|
-
<h1>Header</h1>
|
|
4
|
-
<test
|
|
5
|
-
${props.styles}
|
|
6
|
-
>${props.color}</test>
|
|
7
|
-
|
|
8
|
-
${
|
|
9
|
-
function(){
|
|
10
|
-
|
|
11
|
-
if(props.color === 'red'){
|
|
12
|
-
return `<h1>Red</h1>`
|
|
13
|
-
}else{
|
|
14
|
-
return `<h1>Not Red</h1>`
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
}()
|
|
18
|
-
}
|
|
19
|
-
</div>
|
|
20
|
-
</header>
|