pawajs 1.4.22 → 1.4.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/CHANGELOG.md CHANGED
@@ -8,4 +8,5 @@ CHANGELOG.md
8
8
  + version 1.4.13 - 1.4.16 fixed issues for resuming component
9
9
  + version 1.4.18 - 1.4.19 fixed issue with component inside template and added event modifiers
10
10
  + version 1.4.19 - 1.4.21 made runEffect Global
11
- + version 1.4.22 fixed merger if when the ssr render else and else render down in pawajs engine
11
+ + version 1.4.22 fixed merger if when the ssr render else and else render down in pawajs engine
12
+ + version 1.4.23
package/index.js CHANGED
@@ -833,6 +833,7 @@ const mainAttribute = (el, exp) => {
833
833
  el._mainAttribute[exp.name] = exp.value
834
834
  el._checkStatic()
835
835
  let enter=false
836
+ const context=el._context
836
837
  const evaluate = () => {
837
838
 
838
839
  try {
@@ -848,7 +849,7 @@ const mainAttribute = (el, exp) => {
848
849
  if (checkKeywordsExistence(el._staticContext, expression)) {
849
850
  return ''
850
851
  } else {
851
- const result = el.safeEval(el._context, expression, `error at attribute ${exp.name}`, true)
852
+ const result = el.safeEval(context, expression, `error at attribute ${exp.name}`, true)
852
853
  isBoolean = result
853
854
  if (typeof result !== 'boolean') {
854
855
  return result ?? ''
@@ -915,7 +916,9 @@ const textContentHandler = (el, isName) => {
915
916
  nodesMap.set(node, node.nodeValue);
916
917
  });
917
918
  el._checkStatic()
919
+ const context=el._context
918
920
  const evaluate = () => {
921
+
919
922
  try {
920
923
  textNodes.forEach(textNode => {
921
924
  // Always use original content from map for evaluation
@@ -928,7 +931,7 @@ const textContentHandler = (el, isName) => {
928
931
  } else {
929
932
  if(expression === '')return value
930
933
  el._textContent[expression] = value
931
- const res = el.safeEval(el._context, expression, 'textContent', true)
934
+ const res = el.safeEval(context, expression, 'textContent', true)
932
935
  return String(res ?? '');
933
936
  }
934
937
  });
@@ -1138,6 +1141,7 @@ export const render = (el, contexts = {}, notRender, isName) => {
1138
1141
  render(child, context, number, isName)
1139
1142
  })
1140
1143
  el._callMount()
1144
+ el._clearContext()
1141
1145
  if (el.hasAttribute('p:c') && !el.hasAttribute('p-async')) {
1142
1146
  el.removeAttribute('p:c')
1143
1147
  }
package/merger/for.js CHANGED
@@ -17,14 +17,13 @@ export const merger_for = (el, stateContext, attr, arrayName, arrayItem, indexes
17
17
  }
18
18
  try {
19
19
  if (!func) {
20
- func=el.safeEval(el._context, arrayName, 'for-each');
20
+ func=el.safeEval(context, arrayName, 'for-each');
21
21
  }
22
22
  let array = func(...getEvalValues(context))
23
23
  let update;
24
24
  if (!firstEnter) {
25
25
  const div = document.createElement('div')
26
26
  array.forEach((item, index) => {
27
- const context = el._context
28
27
  const itemContext = {
29
28
  [arrayItem]: item,
30
29
  [indexes]: index,
@@ -94,7 +93,6 @@ export const merger_for = (el, stateContext, attr, arrayName, arrayItem, indexes
94
93
  })
95
94
  Array.from(div.children).forEach((child, index) => {
96
95
  const key = child.getAttribute('for-key') || index
97
- const context = el._context
98
96
  const itemContext = {
99
97
  [arrayItem]: array[index],
100
98
  [indexes]: index,
@@ -151,7 +149,7 @@ export const merger_for = (el, stateContext, attr, arrayName, arrayItem, indexes
151
149
  }
152
150
  if (firstEnter && !resume) {
153
151
  array.forEach((item, index) => {
154
- const context = el._context
152
+ const context = context
155
153
  const itemContext = {
156
154
  [arrayItem]: item,
157
155
  [indexes]: index,
@@ -190,7 +188,6 @@ export const merger_for = (el, stateContext, attr, arrayName, arrayItem, indexes
190
188
  const number={notRender:null,index:null}
191
189
  elementArray.forEach((keyComment) => {
192
190
  if(keyComment.nextElementSibling === null) return
193
- const context = el._context
194
191
  const itemContext = {
195
192
  [arrayItem]: array[keyComment._index],
196
193
  [indexes]: keyComment._index,
@@ -206,9 +203,10 @@ export const merger_for = (el, stateContext, attr, arrayName, arrayItem, indexes
206
203
  message: `Error from For directive ${error.message}`,
207
204
  error: error,
208
205
  template: el._template,
209
- el: el._el
206
+ el: el
210
207
  })
211
208
  }
212
209
  }
210
+ el?._clearContext()
213
211
  return evaluate
214
212
  }
package/merger/if.js CHANGED
@@ -13,6 +13,7 @@ export const merger_if=(el,attr,stateContext,resume=false,{comment,endComment,ch
13
13
  if (resume) {
14
14
  oldChain={id:attr.value}
15
15
  }
16
+ const context=el._context
16
17
  const evaluate = () => {
17
18
  if (endComment.parentElement === null) {
18
19
  el._deleteEffects()
@@ -23,11 +24,11 @@ export const merger_if=(el,attr,stateContext,resume=false,{comment,endComment,ch
23
24
  func =new Map()
24
25
  chained.forEach((item)=>{
25
26
  if(item.condition === 'else')return
26
- let funcs=el.safeEval(el._context,item.exp,'if')
27
+ let funcs=el.safeEval(context,item.exp,'if')
27
28
  func.set(item.exp,funcs)
28
29
  })
29
30
  }
30
- const values = getEvalValues(el._context)
31
+ const values = getEvalValues(context)
31
32
  let current
32
33
  chained.forEach(element => {
33
34
  if (current || element.condition === 'else') return
@@ -57,7 +58,7 @@ export const merger_if=(el,attr,stateContext,resume=false,{comment,endComment,ch
57
58
  }
58
59
  comment.data=`condition ${exp}`
59
60
  parent.insertBefore(newElement, endComment)
60
- render(newElement, el._context)
61
+ render(newElement, context)
61
62
  stateContext._hasRun = true
62
63
  }
63
64
  if (comment.nextSibling !== endComment && oldChain.id !== latestChain.id) {
@@ -110,7 +111,7 @@ export const merger_if=(el,attr,stateContext,resume=false,{comment,endComment,ch
110
111
  number.index = isIndex
111
112
  isIndex++
112
113
  if (number.notRender !== null && isIndex <= number.notRender) return
113
- render(value,el._context,number)
114
+ render(value,context,number)
114
115
  })
115
116
  stateContext._hasRun=true
116
117
  }
@@ -129,5 +130,6 @@ export const merger_if=(el,attr,stateContext,resume=false,{comment,endComment,ch
129
130
  })
130
131
  }
131
132
  }
133
+ el?._clearContext()
132
134
  return evaluate
133
135
  }
package/merger/key.js CHANGED
@@ -13,6 +13,7 @@ export const merger_key=(el,attr,stateContext,resume=false,{comment,endComment,c
13
13
  if (resume) {
14
14
  oldsate=old
15
15
  }
16
+ const context=el._context
16
17
  const evaluate = () => {
17
18
  if (endComment.parentElement === null) {
18
19
  el._deleteEffects()
@@ -21,9 +22,9 @@ export const merger_key=(el,attr,stateContext,resume=false,{comment,endComment,c
21
22
  let value=attr.value
22
23
  let keyValue
23
24
  if (!func) {
24
- func=el.safeEval(el._context,attr.value,'key')
25
+ func=el.safeEval(context,attr.value,'key')
25
26
  }
26
- const values = getEvalValues(el._context)
27
+ const values = getEvalValues(context)
27
28
  let current
28
29
 
29
30
  if (!firstEnter) {
@@ -39,7 +40,7 @@ export const merger_key=(el,attr,stateContext,resume=false,{comment,endComment,c
39
40
  comment.data=`key ${latestState}`
40
41
  endComment.data=`/ key ${latestState}`
41
42
  parent.insertBefore(newElement, endComment)
42
- render(newElement, el._context)
43
+ render(newElement, context)
43
44
  stateContext._hasRun = true
44
45
  }
45
46
  latestState=func(...values)
@@ -52,7 +53,7 @@ export const merger_key=(el,attr,stateContext,resume=false,{comment,endComment,c
52
53
  children.forEach((value, index) => {
53
54
  number.index=index
54
55
  if (number.notRender !== null && index <= number.notRender) return
55
- render(value,el._context,number)
56
+ render(value,context,number)
56
57
  })
57
58
  stateContext._hasRun=true
58
59
  once=true
@@ -100,5 +101,6 @@ export const merger_key=(el,attr,stateContext,resume=false,{comment,endComment,c
100
101
  })
101
102
  }
102
103
  }
104
+ el?._clearContext()
103
105
  return evaluate
104
106
  }
package/merger/switch.js CHANGED
@@ -13,6 +13,7 @@ export const merger_switch=(el,attr,stateContext,resume=false,{comment,endCommen
13
13
  if (resume) {
14
14
  oldChain={id:caseValue.value}
15
15
  }
16
+ const context=el._context
16
17
  const evaluate = () => {
17
18
  if (endComment.parentElement === null) {
18
19
  el._deleteEffects()
@@ -23,12 +24,12 @@ export const merger_switch=(el,attr,stateContext,resume=false,{comment,endCommen
23
24
  func =new Map()
24
25
  chained.forEach((item)=>{
25
26
  if(item.condition === 'default')return
26
- let funcs=safeEval(el._context,item.exp,item.element)
27
+ let funcs=safeEval(context,item.exp,item.element)
27
28
  func.set(item.exp,funcs)
28
29
  })
29
- switchFunc=safeEval(el._context,attr.value,el)
30
+ switchFunc=safeEval(context,attr.value,el)
30
31
  }
31
- const values = getEvalValues(el._context)
32
+ const values = getEvalValues(context)
32
33
  let current
33
34
  chained.forEach(element => {
34
35
  if (current || element.condition === 'default') return
@@ -58,7 +59,7 @@ export const merger_switch=(el,attr,stateContext,resume=false,{comment,endCommen
58
59
  }
59
60
  comment.data=`condition ${exp}`
60
61
  parent.insertBefore(newElement, endComment)
61
- render(newElement, el._context)
62
+ render(newElement, context)
62
63
  stateContext._hasRun = true
63
64
  }
64
65
  if (comment.nextSibling !== endComment && oldChain.id !== latestChain.id) {
@@ -110,7 +111,7 @@ export const merger_switch=(el,attr,stateContext,resume=false,{comment,endCommen
110
111
  number.index = isIndex
111
112
  isIndex++
112
113
  if (number.notRender !== null && isIndex <= number.notRender) return
113
- render(value,el._context,number)
114
+ render(value,context,number)
114
115
  })
115
116
  stateContext._hasRun=true
116
117
  }
@@ -128,5 +129,6 @@ export const merger_switch=(el,attr,stateContext,resume=false,{comment,endCommen
128
129
  })
129
130
  }
130
131
  }
132
+ el?._clearContext()
131
133
  return evaluate
132
134
  }
@@ -103,6 +103,9 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
103
103
  childInsert(false)
104
104
  Promise.resolve().then(()=>{
105
105
  lifeCircle()
106
+
107
+ }).finally(()=>{
108
+ el._clearContext()
106
109
  })
107
110
  storeContext._hasRun=true
108
111
  stateContext=null
@@ -132,6 +135,7 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
132
135
  if (component?._insert) {
133
136
  Object.assign(el._context,component._insert)
134
137
  }
138
+ const context=el._context
135
139
  const propsSetter=()=>{
136
140
  if(Object.entries(el._restProps).length > 0){
137
141
  const findElement=div.querySelector('[--]') || div.querySelector('[rest]')
@@ -183,7 +187,7 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
183
187
  stateContexts?._error?.forEach((error) => {
184
188
  throw Error(error)
185
189
  })
186
- render(child, el._context)
190
+ render(child, context)
187
191
  }
188
192
  }
189
193
  }
@@ -226,7 +230,10 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
226
230
 
227
231
  })
228
232
  }
229
- if(awaits === false)lifeCircle()
233
+ if(awaits === false){
234
+ lifeCircle()
235
+ el._clearContext()
236
+ }
230
237
  stateContexts._hasRun=true
231
238
  keepContext(stateContexts._formerContext)
232
239
  if (stateContexts._transportContext) {
@@ -235,5 +242,5 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
235
242
  }
236
243
  stateContext=formerStateContext
237
244
  __pawaDev.totalComponent++
238
-
245
+
239
246
  }
@@ -28,4 +28,5 @@ export const templates=(el,notRender)=>{
28
28
  element.forEach(child=>{
29
29
  render(child,el._context,isResume?notRender:{ notRender: null, index: null })
30
30
  })
31
+ el?._clearContext()
31
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pawajs",
3
- "version": "1.4.22",
3
+ "version": "1.4.23",
4
4
  "type":"module",
5
5
  "description": "pawajs library (reactive web runtime) for easily building web ui, enhancing html element, micro frontend etc ",
6
6
  "main": "index.js",
package/pawaElement.js CHANGED
@@ -5,12 +5,14 @@ import PawaComponent from './pawaComponent.js';
5
5
 
6
6
  export class PawaElement {
7
7
 
8
+ #context
8
9
  /**
9
10
  *
10
11
  * @param {HTMLElement} element
11
12
  * @param {object} context
12
13
  */
13
- constructor(element,context) {
14
+ constructor(element,context) {
15
+ this.#context=context
14
16
  const div=document.createElement('div'); div.appendChild(element.cloneNode(true))
15
17
  Object.assign(this, {
16
18
  _resetEffects: new Set(), _context: context, _avoidPawaRender: element.hasAttribute('pawa-avoid'),
@@ -25,7 +27,8 @@ constructor(element,context) {
25
27
  _pawaElementComponent: null, _componentTerminate: null, _cacheSetUp: false, _effectsCarrier: null,
26
28
  _pawaElementComponentName: '', _reCallEffect: this.reCallEffect, _ElementEffects: new Map(),
27
29
  _deCompositionElement: false, _restProps: {}, _kill: null, _isKill: false, _scriptFetching: element.hasAttribute('script'),
28
- _scriptDone: false, _underControl: null, safeEval: this.safeEval, _reactiveProps: {}
30
+ _scriptDone: false, _underControl: null, safeEval: this.safeEval, _reactiveProps: {},
31
+ _clearContext:this.clearContext
29
32
  })
30
33
  if (this._lazy) this._componentOrTemplate = true
31
34
  if(this._avoidPawaRender) {
@@ -42,6 +45,7 @@ constructor(element,context) {
42
45
  getChildrenTree(){
43
46
  return Array.from(this._el.children)
44
47
  }
48
+
45
49
  safeEval(context,expression,directive,resolve=false){
46
50
  try{
47
51
  const keys = Object.keys(context);
@@ -146,7 +150,7 @@ constructor(element,context) {
146
150
  })
147
151
  }
148
152
  reCheckStaticContext(){
149
- const context=this._context
153
+ const context=this.context
150
154
  if (this._staticContext.length > 0) {
151
155
  for (const [key,value] of Object.entries(context)) {
152
156
  if (this._staticContext.includes(key)) {
@@ -174,7 +178,6 @@ constructor(element,context) {
174
178
  return animate
175
179
  } catch (error) {
176
180
  console.error(error);
177
-
178
181
  }
179
182
  } else {
180
183
  this._callUnMOunt()
@@ -254,6 +257,11 @@ constructor(element,context) {
254
257
 
255
258
  }
256
259
  }
260
+ clearContext(){
261
+ if (!__pawaDev.tool) {
262
+ this._context={}
263
+ }
264
+ }
257
265
  setProps(){
258
266
  if (this._avoidPawaRender) {
259
267
  return
package/power.js CHANGED
@@ -99,7 +99,7 @@ const checkKeyModifiers = (e, modifiers, eventType) => {
99
99
  };
100
100
 
101
101
  // Shared helper to execute event with debounce/throttle/error handling
102
- const processEventExecution = (el, attrName, modifiers, callback, eventType, directiveName) => {
102
+ const processEventExecution = (el, attrName, modifiers, callback, eventType, directiveName,context) => {
103
103
  const execute = () => {
104
104
  try { callback(); }
105
105
  catch (error) { setPawaDevError({ message: `Error from ${directiveName}-${eventType} directive ${error.message}`, error, template: el._template }); }
@@ -255,6 +255,7 @@ export const event = (el, attr, stateContext) => {
255
255
  if (el._running || checkKeywordsExistence(el._staticContext, attr.value)) {
256
256
  return
257
257
  }
258
+ const context = el._context
258
259
 
259
260
  const directive = attr.name.substring(3); // 'on-click.prevent' → 'click.prevent'
260
261
  const parts = directive.split('.');
@@ -262,7 +263,6 @@ export const event = (el, attr, stateContext) => {
262
263
  const modifiers = new Set(parts.slice(1));
263
264
 
264
265
  el.removeAttribute(attr.name)
265
- const context = el._context
266
266
  const keys = Object.keys(context);
267
267
  const resolvePath = (path, obj) => {
268
268
  return path.split('.').reduce((acc, key) => acc?.[key], obj);
@@ -315,10 +315,10 @@ export const event = (el, attr, stateContext) => {
315
315
  });
316
316
  }
317
317
 
318
- const createBoundCallback = (el, code) => {
319
- const keys = Object.keys(el._context);
318
+ const createBoundCallback = (el, code,context) => {
319
+ const keys = Object.keys(context);
320
320
  const resolvePath = (path, obj) => path.split('.').reduce((acc, key) => acc?.[key], obj);
321
- const values = keys.map((key) => resolvePath(key, el._context));
321
+ const values = keys.map((key) => resolvePath(key, context));
322
322
  const func = new Function(...keys, code);
323
323
  return () => func(...values);
324
324
  };
@@ -326,7 +326,7 @@ const createBoundCallback = (el, code) => {
326
326
  export const mountElement = (el, attr) => {
327
327
  if (el._running) return;
328
328
  try {
329
- const func = createBoundCallback(el, attr.value);
329
+ const func = createBoundCallback(el, attr.value,el._context);
330
330
  el._MountFunctions.push(func);
331
331
  el.removeAttribute(attr.name);
332
332
  } catch (error) {
@@ -341,7 +341,7 @@ export const mountElement = (el, attr) => {
341
341
  export const unMountElement = (el, attr) => {
342
342
  if (el._running) return;
343
343
  try {
344
- const func = createBoundCallback(el, attr.value);
344
+ const func = createBoundCallback(el, attr.value,el._context);
345
345
  el._unMountFunctions.push(func);
346
346
  el.removeAttribute(attr.name);
347
347
  } catch (error) {
@@ -485,6 +485,7 @@ export const documentEvent = (el, attr) => {
485
485
  const resolvePath = (path, obj) => {
486
486
  return path.split('.').reduce((acc, key) => acc?.[key], obj);
487
487
  };
488
+ const values = keys.map((key) => resolvePath(key, el._context));
488
489
  const func = new Function('e', '$element', ...keys, `
489
490
  try{
490
491
  ${attr.value}
@@ -492,7 +493,6 @@ export const documentEvent = (el, attr) => {
492
493
  console.error(error.message, error.stack)
493
494
  __pawaDev.setError({msg: error.message, stack: error.stack, directives: 'out-event'})
494
495
  }`)
495
- const values = keys.map((key) => resolvePath(key, el._context));
496
496
 
497
497
  const handler = (e) => {
498
498
  if (!checkCommonModifiers(e, modifiers)) return;