pawajs 1.4.24 → 1.4.26

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
@@ -10,4 +10,5 @@ CHANGELOG.md
10
10
  + version 1.4.19 - 1.4.21 made runEffect Global
11
11
  + version 1.4.22 fixed merger if when the ssr render else and else render down in pawajs engine
12
12
  + version 1.4.23 fixed _context from production
13
- + version 1.4.24 - add HMR mapping
13
+ + version 1.4.24 - add HMR mapping
14
+ + version 1.4.26 - fixed key getcomment id
package/index.js CHANGED
@@ -527,7 +527,8 @@ const createDeepProxy = (target, callback) => {
527
527
  get(target, property) {
528
528
  const value = target[property];
529
529
  track(target, property);
530
- if (typeof value === "object" && value !== null) {
530
+ // Only proxy plain objects/arrays and skip if already a proxy
531
+ if (typeof value === "object" && value !== null && !value._isPawaProxy) {
531
532
  return createDeepProxy(value, callback);
532
533
  }
533
534
  return value;
@@ -991,7 +992,7 @@ export const render = (el, contexts = {}, notRender, isName) => {
991
992
  return false
992
993
  }
993
994
  if (el.tagName === 'TITLE') {
994
- document.title=el.textContent
995
+ document.title = (el.textContent || '').trim()
995
996
  el.remove()
996
997
  return
997
998
  }
@@ -1032,7 +1033,7 @@ export const render = (el, contexts = {}, notRender, isName) => {
1032
1033
  startsWithSet.forEach(starts => {
1033
1034
 
1034
1035
  el._attributes.forEach(attr => {
1035
- if (attr.name.startsWith('on:')) {
1036
+ if (attr.name.startsWith(starts)) {
1036
1037
  startAttribute = true
1037
1038
  startObject[attr.name] = starts
1038
1039
  }
@@ -79,15 +79,16 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
79
79
  let compo
80
80
  let awaits=false
81
81
  let suspense=''
82
+
82
83
  if (__pawaDev.tool) {
83
84
  const id= crypto.randomUUID()
84
- if (HmrComponentMap.has(stateContexts._name)) {
85
- HmrComponentMap.get(stateContexts._name).push({id:id,template:el._template,el:el,stateContext:stateContexts})
85
+ if (HmrComponentMap.has(stateContexts.component._filePath) && stateContexts.component._filePath) {
86
+ HmrComponentMap.get(stateContexts.component._filePath).push({id:id,template:el._template,el:el,stateContext:stateContexts})
86
87
  }else{
87
- HmrComponentMap.set(stateContexts._name,[{id:id,template:el._template,el:el,stateContext:stateContexts}])
88
+ HmrComponentMap.set(stateContexts.component._filePath,[{id:id,template:el._template,el:el,stateContext:stateContexts}])
88
89
  }
89
90
  el._setUnMount(()=>{
90
- const array=HmrComponentMap.get(stateContexts._name)
91
+ const array=HmrComponentMap.get(stateContexts.component._filePath)
91
92
  if(array){
92
93
  const index=array.findIndex(item => item.id === id)
93
94
  if(index !== -1) array.splice(index,1)
@@ -117,7 +118,7 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
117
118
  }
118
119
  childInsert(false)
119
120
  Promise.resolve().then(()=>{
120
- lifeCircle()
121
+ lifecycle()
121
122
 
122
123
  }).finally(()=>{
123
124
  el._clearContext()
@@ -206,8 +207,8 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
206
207
  }
207
208
  }
208
209
  }
209
- childInsert(awaits?true:false);
210
- const lifeCircle=()=>{
210
+ childInsert(!!awaits);
211
+ const lifecycle=()=>{
211
212
  Promise.resolve().then(()=>{
212
213
  el._component?._hook?.effect.forEach((hook) => {
213
214
 
@@ -246,7 +247,7 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
246
247
  })
247
248
  }
248
249
  if(awaits === false){
249
- lifeCircle()
250
+ lifecycle()
250
251
  el._clearContext()
251
252
  }
252
253
  stateContexts._hasRun=true
@@ -1,4 +1,5 @@
1
1
  import {render} from '../index.js'
2
+ import { pawaWayRemover } from '../utils.js'
2
3
  export const templates=(el,notRender)=>{
3
4
  if (el.hasAttribute('p:store')) {
4
5
  return
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pawajs",
3
- "version": "1.4.24",
3
+ "version": "1.4.26",
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
@@ -23,7 +23,7 @@ export class PawaElement {
23
23
  _elementType: '', _getNode: this.getNode, _componentOrTemplate: false, _props: {}, _isView: null,
24
24
  _isElementComponent: false, _pawaAttribute: {}, _setUnMount: this.setUnMounts, _componentName: '',
25
25
  _attrElement: this.getNewElementByRemovingAttr, _attr: {}, _staticContext: [], _checkStatic: this.reCheckStaticContext,
26
- _callMount: this.mount, _callUnMOunt: this.unMount, _remove: this.remove, _componentChildren: undefined,
26
+ _callMount: this.mount, _callUnmount: this.unMount, _remove: this.remove, _componentChildren: undefined,
27
27
  _pawaElementComponent: null, _componentTerminate: null, _cacheSetUp: false, _effectsCarrier: null,
28
28
  _pawaElementComponentName: '', _reCallEffect: this.reCallEffect, _ElementEffects: new Map(),
29
29
  _deCompositionElement: false, _restProps: {}, _kill: null, _isKill: false, _scriptFetching: element.hasAttribute('script'),
@@ -167,8 +167,8 @@ export class PawaElement {
167
167
  if (typeof this._exitAnimation === 'function') {
168
168
 
169
169
  try {
170
- const animate=this._exitAnimation().then(() => {
171
- this._callUnMOunt()
170
+ const animate=this._exitAnimation().then(async () => {
171
+ await this._callUnmount()
172
172
  this._out = true
173
173
  this._el.remove()
174
174
  if (callback) {
@@ -180,7 +180,7 @@ export class PawaElement {
180
180
  console.error(error);
181
181
  }
182
182
  } else {
183
- this._callUnMOunt()
183
+ this._callUnmount()
184
184
  this._out=true
185
185
  this._el.remove()
186
186
  if (callback) {
@@ -202,7 +202,7 @@ export class PawaElement {
202
202
  if (child?._el) {
203
203
  child._out = true
204
204
  child._deleteEffects()
205
- child._callUnMOunt()
205
+ child._callUnmount()
206
206
  }
207
207
  } else if (child.nodeType === 8) {
208
208
  if (child?._controlComponent) {
package/power.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { createEffect } from './reactive.js';
2
2
  import { render, $state, keepContext,restoreContext} from './index.js';
3
3
  import { PawaComment, PawaElement } from './pawaElement.js';
4
- import { processNode, pawaWayRemover,getComment,getEndComment, safeEval, getEvalValues, setPawaDevError, checkKeywordsExistence } from './utils.js';
4
+ import { processNode, pawaWayRemover,getComment,getEndComment, safeEval, getEvalValues, setPawaDevError, checkKeywordsExistence, evaluation } from './utils.js';
5
5
  import {normal_Switch} from './normal/Switch.js'
6
6
  import {normal_If} from './normal/If.js'
7
7
  import {normal_For} from './normal/For.js'
@@ -176,13 +176,19 @@ export const If = (el, attr, stateContext,resume=false,notRender,stopResume) =>
176
176
  let dataComment
177
177
  let id=attr.name.slice(5)
178
178
  const children=[]
179
- const setComment=(c)=>comment=c
180
- const setEndComment=(c)=>endComment=c
181
- getComment(el,setComment,id)
182
- getEndComment(comment,setEndComment,id,children)
183
- const numberIfChildren=notRender.index + children.length - 2
184
- notRender.notRender=numberIfChildren
185
- resumer.resume_if?.(el,attr,stateContext,{comment,endComment,id,children})
179
+ try {
180
+ const setComment=(c)=>comment=c
181
+ const setEndComment=(c)=>endComment=c
182
+ getComment(el,setComment,id)
183
+ getEndComment(comment,setEndComment,id,children)
184
+ const numberIfChildren=notRender.index + children.length - 2
185
+ notRender.notRender=numberIfChildren
186
+ resumer.resume_if?.(el,attr,stateContext,{comment,endComment,id,children})
187
+
188
+ } catch (error) {
189
+ console.log(error,el ,attr,id);
190
+
191
+ }
186
192
 
187
193
  }
188
194
  }
@@ -263,20 +269,15 @@ export const event = (el, attr, stateContext) => {
263
269
  const modifiers = new Set(parts.slice(1));
264
270
 
265
271
  el.removeAttribute(attr.name)
266
- const keys = Object.keys(context);
267
- const resolvePath = (path, obj) => {
268
- return path.split('.').reduce((acc, key) => acc?.[key], obj);
272
+
273
+ const executeEvent = (e) => {
274
+ try {
275
+ const eventContext = { ...context, e };
276
+ evaluation(eventContext, attr.value);
277
+ } catch (error) {
278
+ __pawaDev.setError({ el: el, msg: error.message, stack: error.stack, directives: 'on-event' });
279
+ }
269
280
  };
270
- const values = keys.map((key) => resolvePath(key, context));
271
-
272
- const func = new Function('e', ...keys, `
273
- try{
274
- ${attr.value}
275
- }catch(error){
276
- console.error(error.message, error.stack)
277
- __pawaDev.setError({el: e.target, msg: error.message, stack: error.stack, directives: 'on-event'})
278
- }
279
- `)
280
281
 
281
282
  const handler = (e) => {
282
283
  if (!checkCommonModifiers(e, modifiers)) return;
@@ -297,7 +298,7 @@ export const event = (el, attr, stateContext) => {
297
298
  if (modifiers.has('stop')) e.stopPropagation();
298
299
 
299
300
  // ========== EXECUTION ==========
300
- processEventExecution(el, attr.name, modifiers, () => func(e, ...values), eventType, 'on');
301
+ processEventExecution(el, attr.name, modifiers, () => executeEvent(e), eventType, 'on');
301
302
  };
302
303
 
303
304
  const options = {
@@ -481,18 +482,15 @@ export const documentEvent = (el, attr) => {
481
482
  if (!eventType) return;
482
483
 
483
484
  el.removeAttribute(attr.name)
484
- const keys = Object.keys(el._context);
485
- const resolvePath = (path, obj) => {
486
- return path.split('.').reduce((acc, key) => acc?.[key], obj);
487
- };
488
- const values = keys.map((key) => resolvePath(key, el._context));
489
- const func = new Function('e', '$element', ...keys, `
490
- try{
491
- ${attr.value}
492
- }catch(error){
493
- console.error(error.message, error.stack)
494
- __pawaDev.setError({msg: error.message, stack: error.stack, directives: 'out-event'})
495
- }`)
485
+
486
+ const executeOutEvent = (e) => {
487
+ try {
488
+ const eventContext = { ...el._context, e, $element: el };
489
+ evaluation(eventContext, attr.value);
490
+ } catch (error) {
491
+ __pawaDev.setError({ msg: error.message, stack: error.stack, directives: 'out-event' });
492
+ }
493
+ };
496
494
 
497
495
  const handler = (e) => {
498
496
  if (!checkCommonModifiers(e, modifiers)) return;
@@ -507,7 +505,7 @@ export const documentEvent = (el, attr) => {
507
505
  if (modifiers.has('stop')) e.stopPropagation();
508
506
 
509
507
  // ========== EXECUTION ==========
510
- processEventExecution(el, attr.name, modifiers, () => func(e, el, ...values), eventType, 'out');
508
+ processEventExecution(el, attr.name, modifiers, () => executeOutEvent(e), eventType, 'out');
511
509
  }
512
510
 
513
511
  const options = {
@@ -592,7 +590,7 @@ export const Key = (el, attr, stateContext,resume=false,notRender,stopResume) =>
592
590
  let comment
593
591
  let endComment
594
592
  let dataComment
595
- let id=attr.name.slice(10)
593
+ let id=attr.name.slice(6)
596
594
  const children=[]
597
595
  const setComment=(c)=>comment=c
598
596
  const setEndComment=(c)=>endComment=c
package/utils.js CHANGED
@@ -1,3 +1,5 @@
1
+ const evalCache = new Map();
2
+ const templateFnCache = new Map();
1
3
 
2
4
  export const splitAndAdd = str => str.split('-').join('').toUpperCase();
3
5
 
@@ -55,12 +57,15 @@ export const extractContextValues = (context) => {
55
57
 
56
58
  export const evaluation=(context,exp) => {
57
59
  try {
58
- const keys = Object.keys(context);
59
- const resolvePath = (path, obj) => {
60
- return path.split('.').reduce((acc, key) => acc?.[key], obj);
61
- };
62
- const values = keys.map((key) => resolvePath(key, context));
63
- return new Function(...keys,`return ${exp}`)(...values)
60
+ const keys = Object.keys(context);
61
+ const cacheKey = `${keys.join(',')}:${exp}`;
62
+
63
+ let fn = evalCache.get(cacheKey);
64
+ if (!fn) {
65
+ fn = new Function(...keys, `return ${exp}`);
66
+ evalCache.set(cacheKey, fn);
67
+ }
68
+ return fn(...getEvalValues(context));
64
69
  } catch (e) {
65
70
  throw e
66
71
  }
@@ -130,19 +135,20 @@ export const propsValidator=(obj={},propsAttri,name,template,el)=>{
130
135
  export const safeEval=(context,expression,el,resolve=false)=>{
131
136
  try{
132
137
  const keys = Object.keys(context);
133
- const resolvePath = (path, obj) => {
134
- return path.split('.').reduce((acc, key) => acc?.[key], obj);
135
- };
138
+ const cacheKey = `${keys.join(',')}:${expression}`;
139
+
140
+ let fn = evalCache.get(cacheKey);
141
+ if (!fn) {
142
+ fn = new Function(...keys, `return ${expression}`);
143
+ evalCache.set(cacheKey, fn);
144
+ }
145
+
136
146
  if(resolve){
137
- return new Function(...keys,`
138
- return ${expression}
139
- `)(...getEvalValues(context))
140
- }else{
141
- return new Function(...keys,`
142
- return ${expression}
143
- `)
147
+ return fn(...getEvalValues(context))
144
148
  }
145
149
 
150
+ return fn;
151
+
146
152
  }catch(error){
147
153
  setPawaDevError({
148
154
  message:`Error : ${error.message} ${error.stack}`,