pawa-ssr 1.2.4 → 1.2.5
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 +37 -2
- package/package.json +1 -1
- package/pawaElement.js +43 -6
- package/power.js +32 -15
package/index.js
CHANGED
|
@@ -345,6 +345,13 @@ appContext.component._prop={children,...el._props,...slots}
|
|
|
345
345
|
await fn(stateContext,app)
|
|
346
346
|
} catch (error) {
|
|
347
347
|
console.error(`Error in beforeCall for ${el._componentName}:`, error.message,error.stack)
|
|
348
|
+
__pawaDev.setError({
|
|
349
|
+
el:el,
|
|
350
|
+
msg:`from compoBeforeCall${el._componentName}:`+ error.message + error.stack,
|
|
351
|
+
directives:'plugin',
|
|
352
|
+
stack:error.stack,
|
|
353
|
+
template:el?._template,
|
|
354
|
+
})
|
|
348
355
|
}
|
|
349
356
|
}
|
|
350
357
|
|
|
@@ -353,12 +360,20 @@ appContext.component._prop={children,...el._props,...slots}
|
|
|
353
360
|
let compo=""
|
|
354
361
|
try{
|
|
355
362
|
if(done){
|
|
363
|
+
|
|
356
364
|
store.getStore().stateContext=appContext
|
|
357
365
|
compo=await component.component(app)
|
|
358
366
|
}
|
|
359
367
|
|
|
360
368
|
}catch(error){
|
|
361
369
|
console.error(`error from PawaComponent.${appContext.component._name}`,error.message,error.stack)
|
|
370
|
+
__pawaDev.setError({
|
|
371
|
+
el:el,
|
|
372
|
+
msg:`error from PawaComponent.${appContext.component._name}`+ error.message + error.stack,
|
|
373
|
+
directives:el.tagName,
|
|
374
|
+
stack:error.stack,
|
|
375
|
+
template:el?._template,
|
|
376
|
+
})
|
|
362
377
|
}
|
|
363
378
|
if (appContext?.insert){
|
|
364
379
|
Object.assign(el._context,appContext.insert)
|
|
@@ -424,7 +439,13 @@ appContext.component._prop={children,...el._props,...slots}
|
|
|
424
439
|
store.getStore().stateContext=appContext.formerContext
|
|
425
440
|
} catch (error) {
|
|
426
441
|
console.log(error.message,error.stack,`at ${el.tagName} component`);
|
|
427
|
-
|
|
442
|
+
__pawaDev.setError({
|
|
443
|
+
el:el,
|
|
444
|
+
msg:`from ${el.tagName} component`,
|
|
445
|
+
directives:'component',
|
|
446
|
+
stack:error.stack,
|
|
447
|
+
template:el?._template,
|
|
448
|
+
})
|
|
428
449
|
}
|
|
429
450
|
}
|
|
430
451
|
const templates=async(el,context)=>{
|
|
@@ -478,7 +499,7 @@ const textContentHandler = async(el) => {
|
|
|
478
499
|
|
|
479
500
|
const expressions = extractAtExpressions(value);
|
|
480
501
|
expressions.forEach(({ fullMatch, expression }) => {
|
|
481
|
-
const func =
|
|
502
|
+
const func = el._evaluateExpr(
|
|
482
503
|
expression,
|
|
483
504
|
el._context,
|
|
484
505
|
`from text interpolation @{} - ${expression} at ${currentHtmlString}`
|
|
@@ -494,6 +515,13 @@ const textContentHandler = async(el) => {
|
|
|
494
515
|
} catch (error) {
|
|
495
516
|
console.warn(`error at ${el._template} textcontent`);
|
|
496
517
|
console.error(error.message, error.stack,`error at ${el._template} textcontent`);
|
|
518
|
+
__pawaDev.setError({
|
|
519
|
+
el:el,
|
|
520
|
+
msg:`Error from textHandler`+ error.message + error.stack,
|
|
521
|
+
directives:el.tagName,
|
|
522
|
+
stack:error.stack,
|
|
523
|
+
template:el?._template,
|
|
524
|
+
})
|
|
497
525
|
}
|
|
498
526
|
};
|
|
499
527
|
|
|
@@ -536,6 +564,13 @@ const attributeHandler =async (el, attr) => {
|
|
|
536
564
|
}
|
|
537
565
|
} catch (error) {
|
|
538
566
|
console.log(error.message, error.stack);
|
|
567
|
+
__pawaDev.setError({
|
|
568
|
+
el:el,
|
|
569
|
+
msg:`error from Attribute Handler`+ error.message + error.stack,
|
|
570
|
+
directives:'Attribute Handler',
|
|
571
|
+
stack:error.stack,
|
|
572
|
+
template:el?._template,
|
|
573
|
+
})
|
|
539
574
|
}
|
|
540
575
|
};
|
|
541
576
|
|
package/package.json
CHANGED
package/pawaElement.js
CHANGED
|
@@ -4,6 +4,7 @@ import {components} from 'pawajs'
|
|
|
4
4
|
import PawaComponent from "./pawaComponent.js"
|
|
5
5
|
import { evaluateExpr, splitAndAdd,replaceTemplateOperators } from "./utils.js"
|
|
6
6
|
|
|
7
|
+
const expressionCache = new Map();
|
|
7
8
|
// changed the hydrateProps
|
|
8
9
|
|
|
9
10
|
class PawaElement {
|
|
@@ -37,6 +38,7 @@ class PawaElement {
|
|
|
37
38
|
this._setError=this.setError
|
|
38
39
|
this._hydrateProps={}
|
|
39
40
|
this._resumeAttr=''
|
|
41
|
+
this._evaluateExpr=this.evaluateExpr
|
|
40
42
|
this._reArrangeAttri=this.reArrange
|
|
41
43
|
this._replaceResumeAttr=this.replaceResumeAttr
|
|
42
44
|
this._setResumeAttr=this.setResumeAttr
|
|
@@ -117,7 +119,7 @@ class PawaElement {
|
|
|
117
119
|
array[index]=newName
|
|
118
120
|
const toString=array.join(';')
|
|
119
121
|
this._el.setAttribute('p:c',toString)
|
|
120
|
-
|
|
122
|
+
this._resumeAttr=toString
|
|
121
123
|
}else{
|
|
122
124
|
ele.setAttribute(newName,value)
|
|
123
125
|
ele.setAttribute('p:c',`${newName};`)
|
|
@@ -172,14 +174,14 @@ class PawaElement {
|
|
|
172
174
|
createError({message,stack}){
|
|
173
175
|
this._error.push({message,stack})
|
|
174
176
|
}
|
|
175
|
-
|
|
177
|
+
//set Component props
|
|
176
178
|
setProps(){
|
|
177
179
|
if (this._componentName) {
|
|
178
180
|
const allServerAttr=getPawaAttributes()
|
|
179
181
|
this._el.attributes.forEach(attr=>{
|
|
180
|
-
if(!allServerAttr.has(attr.name)){
|
|
182
|
+
if(!allServerAttr.has(attr.name) ){
|
|
181
183
|
if ( !attr.name.startsWith(':')) {
|
|
182
|
-
if( attr.name.startsWith('c-') || attr.name.startsWith('p:c')) return
|
|
184
|
+
if( attr.name.startsWith('c-') || attr.name.startsWith('p:c') || attr.name.startsWith('state-')) return
|
|
183
185
|
let name=''
|
|
184
186
|
if (attr.name.startsWith('-')) {
|
|
185
187
|
name=attr.name.slice(1)
|
|
@@ -192,7 +194,7 @@ class PawaElement {
|
|
|
192
194
|
this._hydrateProps[attr.name.slice(1)]=attr.value
|
|
193
195
|
if(attr.value === '') attr.value=true;
|
|
194
196
|
try {
|
|
195
|
-
const func = evaluateExpr(`()=>{
|
|
197
|
+
const func = this.evaluateExpr(`()=>{
|
|
196
198
|
const prop= ${replaceTemplateOperators(attr.value)};
|
|
197
199
|
if(prop === '')return prop
|
|
198
200
|
return prop
|
|
@@ -202,12 +204,47 @@ class PawaElement {
|
|
|
202
204
|
this._props[name]=func
|
|
203
205
|
} catch (error) {
|
|
204
206
|
console.log(error.message,error.stack)
|
|
205
|
-
|
|
207
|
+
__pawaDev.setError({
|
|
208
|
+
el:this._el,
|
|
209
|
+
msg:`errors while setting props at runtime ${error.message}`,
|
|
210
|
+
directives:'setting props',
|
|
211
|
+
stack:error.stack,
|
|
212
|
+
template:el?._template,
|
|
213
|
+
})
|
|
206
214
|
}
|
|
207
215
|
}
|
|
208
216
|
}
|
|
209
217
|
})
|
|
210
218
|
}
|
|
211
219
|
}
|
|
220
|
+
evaluateExpr(expr, context = {},error){
|
|
221
|
+
try {
|
|
222
|
+
const keys = Object.keys(context);
|
|
223
|
+
// Create a cache key based on the expression and the available context keys
|
|
224
|
+
// We sort keys to ensure consistent cache hits regardless of key order
|
|
225
|
+
const cacheKey = expr + '|||' + keys.sort().join(',');
|
|
226
|
+
|
|
227
|
+
let func = expressionCache.get(cacheKey);
|
|
228
|
+
if (!func) {
|
|
229
|
+
func = new Function(...keys, `
|
|
230
|
+
const require=null
|
|
231
|
+
return ${expr}`);
|
|
232
|
+
expressionCache.set(cacheKey, func);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const values = keys.map((key) => context[key]);
|
|
236
|
+
return func(...values);
|
|
237
|
+
} catch (err) {
|
|
238
|
+
console.error(`Evaluation failed for: ${expr}`,error,err.message,err.stack);
|
|
239
|
+
__pawaDev.setError({
|
|
240
|
+
el:this._el,
|
|
241
|
+
msg:`${error} ${err.message}`,
|
|
242
|
+
directives:'expression',
|
|
243
|
+
stack:err.stack,
|
|
244
|
+
template:this._el?._template,
|
|
245
|
+
})
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
};
|
|
212
249
|
}
|
|
213
250
|
export default PawaElement
|
package/power.js
CHANGED
|
@@ -43,7 +43,7 @@ let current
|
|
|
43
43
|
let latestChain
|
|
44
44
|
chained.forEach((item)=>{
|
|
45
45
|
if(item.condition === 'else' || current)return
|
|
46
|
-
const result =
|
|
46
|
+
const result = el._evaluateExpr(item.exp, el._context,`at condition directives check - ${item.exp} at ${item.element.toString()}`);
|
|
47
47
|
current=result
|
|
48
48
|
if (current) {
|
|
49
49
|
latestChain={
|
|
@@ -117,8 +117,7 @@ let latestChain
|
|
|
117
117
|
export const Switch = async(el, attr) => {
|
|
118
118
|
if (el._running) return;
|
|
119
119
|
el._running = true;
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
|
|
122
121
|
const nextSiblings = el.nextElementSibling || null;
|
|
123
122
|
const cases =el.getAttribute('case')
|
|
124
123
|
const chained=[{
|
|
@@ -156,10 +155,10 @@ try {
|
|
|
156
155
|
let func=new Map()
|
|
157
156
|
let current
|
|
158
157
|
let latestChain
|
|
159
|
-
const switchFunc=
|
|
158
|
+
const switchFunc=el._evaluateExpr(attr.value,el._context,`at switch directive ${attr.value}`)
|
|
160
159
|
chained.forEach((item)=>{
|
|
161
160
|
if(item.condition === 'default' || current)return
|
|
162
|
-
const result = switchFunc ===
|
|
161
|
+
const result = switchFunc === el._evaluateExpr(item.exp, el._context,`at condition directives check case - ${item.exp} ${item.element.toString()}`);
|
|
163
162
|
current=result
|
|
164
163
|
if (current || item.condition === 'default') {
|
|
165
164
|
latestChain={
|
|
@@ -231,9 +230,6 @@ const switchFunc=evaluateExpr(attr.value,el._context,`at switch directive ${attr
|
|
|
231
230
|
comment.parentElement.insertBefore(template, endComment);
|
|
232
231
|
// No element rendered
|
|
233
232
|
}
|
|
234
|
-
} catch (error) {
|
|
235
|
-
console.log(error.message,error.stack,`at switch directive ${el._template}`)
|
|
236
|
-
}
|
|
237
233
|
};
|
|
238
234
|
|
|
239
235
|
export const For=async(el,attr)=>{
|
|
@@ -258,7 +254,7 @@ export const For=async(el,attr)=>{
|
|
|
258
254
|
const arrayItems=itemPart.split(',')
|
|
259
255
|
const arrayItem=arrayItems[0].trim()
|
|
260
256
|
const indexes=arrayItems[1]
|
|
261
|
-
const array=
|
|
257
|
+
const array=el._evaluateExpr(arrayName,el._context,`at for directives check - ${attr.value}`)
|
|
262
258
|
const copyElement=el.cloneNode(true)
|
|
263
259
|
const store=[]
|
|
264
260
|
Array.from(copyElement.attributes).forEach(at=>{
|
|
@@ -326,7 +322,14 @@ export const For=async(el,attr)=>{
|
|
|
326
322
|
}
|
|
327
323
|
|
|
328
324
|
} catch (error) {
|
|
329
|
-
console.error(error.message,error.stack
|
|
325
|
+
console.error(error.message,error.stack)
|
|
326
|
+
__pawaDev.setError({
|
|
327
|
+
el:el,
|
|
328
|
+
msg:`error from for-each ${attr.value}`+ error.message + error.stack,
|
|
329
|
+
directives:'for-each',
|
|
330
|
+
stack:error.stack,
|
|
331
|
+
template:el?._template,
|
|
332
|
+
})
|
|
330
333
|
}
|
|
331
334
|
}
|
|
332
335
|
|
|
@@ -336,14 +339,21 @@ export const State=async(el,attr)=>{
|
|
|
336
339
|
}
|
|
337
340
|
try {
|
|
338
341
|
|
|
339
|
-
const result=evaluateExpr(attr.value,el._context,`at state directive ${attr.name}=${attr.value}`)
|
|
340
342
|
const name=attr.name.split('-')[1]
|
|
341
343
|
el._replaceResumeAttr(attr.name,`c-$-${name}`,attr.value)
|
|
344
|
+
el.removeAttribute(attr.name)
|
|
345
|
+
const result=el._evaluateExpr(attr.value,el._context,`at state directive ${attr.name}=${attr.value}`)
|
|
342
346
|
// el.setAttribute(`resume-state-${name}`,attr.value)
|
|
343
347
|
el._context[name]={value:result}
|
|
344
|
-
el.removeAttribute(attr.name)
|
|
345
348
|
} catch (error) {
|
|
346
|
-
console.log(error.message,error.stack
|
|
349
|
+
console.log(error.message,error.stack)
|
|
350
|
+
__pawaDev.setError({
|
|
351
|
+
el:el,
|
|
352
|
+
msg:`error from state ${attr.name} : ${attr.value}`+ error.message + error.stack,
|
|
353
|
+
directives:el.tagName,
|
|
354
|
+
stack:error.stack,
|
|
355
|
+
template:el?._template,
|
|
356
|
+
})
|
|
347
357
|
}
|
|
348
358
|
|
|
349
359
|
}
|
|
@@ -371,7 +381,7 @@ export const Key=async(el,attr)=>{
|
|
|
371
381
|
template.appendChild(clone)
|
|
372
382
|
el.replaceWith(endComment)
|
|
373
383
|
endComment.parentElement.insertBefore(comment,endComment)
|
|
374
|
-
const func=
|
|
384
|
+
const func=el._evaluateExpr(attr.value,el._context,`error at Key - ${attr.name} = ${attr.value}`)
|
|
375
385
|
endComment.parentElement.insertBefore(template,endComment)
|
|
376
386
|
comment.data=`key(${func})@-$@-$@${dirId}`
|
|
377
387
|
endComment.data=`key(${func})@-$@-$@${dirId}`
|
|
@@ -381,6 +391,13 @@ export const Key=async(el,attr)=>{
|
|
|
381
391
|
endComment.parentElement.insertBefore(newElement,endComment)
|
|
382
392
|
await render(newElement,el._context)
|
|
383
393
|
}catch(error){
|
|
384
|
-
console.error(error.message,error.stack
|
|
394
|
+
console.error(error.message,error.stack)
|
|
395
|
+
__pawaDev.setError({
|
|
396
|
+
el:el,
|
|
397
|
+
msg:`error from Key at ${attr.value}`+ error.message + error.stack,
|
|
398
|
+
directives:el.tagName,
|
|
399
|
+
stack:error.stack,
|
|
400
|
+
template:el?._template,
|
|
401
|
+
})
|
|
385
402
|
}
|
|
386
403
|
}
|