pawa-ssr 1.0.21 → 1.0.23
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/index.js +14 -10
- package/package.json +1 -1
- package/pawaElement.js +15 -3
- package/test/index.js +4 -4
- package/utils.js +6 -2
package/index.js
CHANGED
|
@@ -11,7 +11,9 @@ exports.getPawaComponentsMap =()=>{
|
|
|
11
11
|
return components ;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
let isDevelopment
|
|
15
|
+
const getDevelopment=()=>isDevelopment
|
|
16
|
+
exports.getDevelopment=getDevelopment
|
|
15
17
|
const $state = (arg) => {
|
|
16
18
|
return {
|
|
17
19
|
value: arg
|
|
@@ -194,7 +196,8 @@ stateContext._name=el._componentName
|
|
|
194
196
|
children,
|
|
195
197
|
app:{
|
|
196
198
|
insert,
|
|
197
|
-
useValidateProps
|
|
199
|
+
useValidateProps,
|
|
200
|
+
useInnerContext:()=>el._context
|
|
198
201
|
},
|
|
199
202
|
...slots,
|
|
200
203
|
...el._props
|
|
@@ -221,19 +224,18 @@ stateContext._name=el._componentName
|
|
|
221
224
|
}
|
|
222
225
|
|
|
223
226
|
div.innerHTML=compo
|
|
224
|
-
|
|
225
|
-
const findElement=div.querySelector('[--]') || div.querySelector('[rest]')
|
|
227
|
+
const findElement=div.querySelector('[--]') || div.querySelector('[r-]')
|
|
226
228
|
if (findElement) {
|
|
227
|
-
for (const [key,value] of Object.entries(el
|
|
229
|
+
for (const [key,value] of Object.entries(el?._restProps)) {
|
|
228
230
|
findElement.setAttribute(value.name,value.value)
|
|
229
|
-
findElement.removeAttribute('--')
|
|
230
|
-
findElement.removeAttribute('rest')
|
|
231
231
|
}
|
|
232
|
-
|
|
232
|
+
findElement.removeAttribute('--')
|
|
233
|
+
findElement.removeAttribute('r-')
|
|
234
|
+
|
|
233
235
|
}
|
|
234
236
|
for (const fn of compoAfterCall) {
|
|
235
237
|
try {
|
|
236
|
-
fn(stateContext,div?.firstElementChild)
|
|
238
|
+
fn(stateContext,div?.firstElementChild,el)
|
|
237
239
|
} catch (error) {
|
|
238
240
|
console.error(error.message,error.stack)
|
|
239
241
|
}
|
|
@@ -499,6 +501,7 @@ const render = (el, contexts = {}) => {
|
|
|
499
501
|
render(child,el._context)
|
|
500
502
|
})
|
|
501
503
|
}
|
|
504
|
+
el._setError()
|
|
502
505
|
}
|
|
503
506
|
exports.render=render
|
|
504
507
|
const { If,Else,ElseIf,For } = require('./power.js');
|
|
@@ -508,7 +511,8 @@ const directives={
|
|
|
508
511
|
's-else-if':ElseIf,
|
|
509
512
|
's-for':For
|
|
510
513
|
}
|
|
511
|
-
exports.startApp = (html, context = {}) => {
|
|
514
|
+
exports.startApp = (html, context = {},devlopment=false) => {
|
|
515
|
+
isDevelopment=devlopment
|
|
512
516
|
const app=new DOMParser()
|
|
513
517
|
const {document}=parseHTML()
|
|
514
518
|
const body= app.parseFromString(html,'text/html')
|
package/package.json
CHANGED
package/pawaElement.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { HTMLElement, parseHTML } = require("linkedom")
|
|
2
|
-
const { getAllServerAttrArray, getPawaComponentsMap } =require("./index.js")
|
|
2
|
+
const { getAllServerAttrArray, getPawaComponentsMap, getDevelopment } =require("./index.js")
|
|
3
3
|
const PawaComponent = require("./pawaComponent.js")
|
|
4
4
|
const { evaluateExpr, splitAndAdd,replaceTemplateOperators } =require("./utils.js")
|
|
5
5
|
|
|
@@ -23,8 +23,12 @@ class PawaElement {
|
|
|
23
23
|
this._template=element.outerHTML
|
|
24
24
|
this._component=null
|
|
25
25
|
this._componentName=''
|
|
26
|
+
/**@type {Array<{message:string,stack:string}>} */
|
|
27
|
+
this._error=[]
|
|
26
28
|
this._running=false
|
|
27
29
|
this._hasForOrIf=this.hasForOrIf
|
|
30
|
+
this._createError=this.createError
|
|
31
|
+
this._setError=this.setError
|
|
28
32
|
if(this._avoidPawaRender){
|
|
29
33
|
element.removeAttribute('s-pawa-avoid')
|
|
30
34
|
Array.from(element.children).forEach((child) => {
|
|
@@ -76,12 +80,19 @@ class PawaElement {
|
|
|
76
80
|
})
|
|
77
81
|
this._componentChildren=this._el.innerHTML
|
|
78
82
|
}else{
|
|
79
|
-
if(this._el.
|
|
83
|
+
if(this._el.hasAttribute('client')){
|
|
80
84
|
this._el.removeAttribute('client')
|
|
81
85
|
}
|
|
82
86
|
}
|
|
83
87
|
}
|
|
84
|
-
|
|
88
|
+
setError(){
|
|
89
|
+
if (getDevelopment() && this._error.length > 0) {
|
|
90
|
+
this._el.setAttribute('ssr-error',JSON.stringify(this._error))
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
createError({message,stack}){
|
|
94
|
+
this._error.push({message,stack})
|
|
95
|
+
}
|
|
85
96
|
//set Component props
|
|
86
97
|
setProps(){
|
|
87
98
|
if (this._componentName) {
|
|
@@ -105,6 +116,7 @@ class PawaElement {
|
|
|
105
116
|
this._props[name]=func
|
|
106
117
|
} catch (error) {
|
|
107
118
|
console.log(error.message,error.stack)
|
|
119
|
+
this._createError({message:error.message,stack:error.stack})
|
|
108
120
|
}
|
|
109
121
|
}
|
|
110
122
|
}
|
package/test/index.js
CHANGED
|
@@ -6,10 +6,10 @@ const component=({app})=>{
|
|
|
6
6
|
app.insert({user,array})
|
|
7
7
|
return `
|
|
8
8
|
<div>
|
|
9
|
-
<h1
|
|
9
|
+
<h1 -->
|
|
10
10
|
<span>Hello World</span>
|
|
11
|
-
<span s-if="
|
|
12
|
-
<span s-else
|
|
11
|
+
<span s-if="users">Allwell</span>
|
|
12
|
+
<span s-else>@(man.value)</span>
|
|
13
13
|
</h1>
|
|
14
14
|
<div s-for="items in array" s-pawa-avoid>
|
|
15
15
|
<span>@(items)</span>
|
|
@@ -25,5 +25,5 @@ const html=()=>{
|
|
|
25
25
|
</div>
|
|
26
26
|
`
|
|
27
27
|
}
|
|
28
|
-
const newHtml=pawa.startApp(html())
|
|
28
|
+
const newHtml=pawa.startApp(html(),{},true)
|
|
29
29
|
console.log(newHtml.toString())
|
package/utils.js
CHANGED
|
@@ -37,7 +37,8 @@ exports.matchRoute = (pattern, path) => {
|
|
|
37
37
|
};
|
|
38
38
|
exports.sanitizeTemplate = (temp) => {
|
|
39
39
|
if (typeof temp !== 'string') return '';
|
|
40
|
-
return temp.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi, '');
|
|
40
|
+
// return temp.replace(/<script\b[^>]*>([\s\S]*?)<\/script>/gi, '');
|
|
41
|
+
return temp
|
|
41
42
|
};
|
|
42
43
|
/**
|
|
43
44
|
* Safely evaluates a JavaScript expression in a sandbox.
|
|
@@ -47,7 +48,7 @@ exports.sanitizeTemplate = (temp) => {
|
|
|
47
48
|
* @param {string} error - pass in error message
|
|
48
49
|
* @returns {any} - The result of the evaluated expression or null on error.
|
|
49
50
|
*/
|
|
50
|
-
exports.evaluateExpr = (expr, context = {},error) => {
|
|
51
|
+
exports.evaluateExpr = (expr, context = {},error,element) => {
|
|
51
52
|
try {
|
|
52
53
|
const keys = Object.keys(context);
|
|
53
54
|
const resolvePath = (path, obj) => {
|
|
@@ -59,6 +60,9 @@ const values = keys.map((key) => resolvePath(key, context));
|
|
|
59
60
|
return ${expr}`)(...values)
|
|
60
61
|
} catch (err) {
|
|
61
62
|
console.error(`Evaluation failed for: ${expr}`,error,err.message,err.stack);
|
|
63
|
+
if (element) {
|
|
64
|
+
element._createError({message:`${error} ${err.message}`,stack:err.stack})
|
|
65
|
+
}
|
|
62
66
|
return null;
|
|
63
67
|
}
|
|
64
68
|
};
|