pawajs 1.4.24 → 1.4.25
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 +4 -3
- package/normal/component.js +9 -8
- package/normal/template.js +1 -0
- package/package.json +1 -1
- package/pawaElement.js +5 -5
- package/power.js +20 -28
- package/utils.js +22 -16
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
|
-
|
|
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(
|
|
1036
|
+
if (attr.name.startsWith(starts)) {
|
|
1036
1037
|
startAttribute = true
|
|
1037
1038
|
startObject[attr.name] = starts
|
|
1038
1039
|
}
|
package/normal/component.js
CHANGED
|
@@ -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.
|
|
85
|
-
HmrComponentMap.get(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.
|
|
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.
|
|
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
|
-
|
|
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
|
|
210
|
-
const
|
|
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
|
-
|
|
250
|
+
lifecycle()
|
|
250
251
|
el._clearContext()
|
|
251
252
|
}
|
|
252
253
|
stateContexts._hasRun=true
|
package/normal/template.js
CHANGED
package/package.json
CHANGED
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,
|
|
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.
|
|
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.
|
|
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.
|
|
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'
|
|
@@ -263,20 +263,15 @@ export const event = (el, attr, stateContext) => {
|
|
|
263
263
|
const modifiers = new Set(parts.slice(1));
|
|
264
264
|
|
|
265
265
|
el.removeAttribute(attr.name)
|
|
266
|
-
|
|
267
|
-
const
|
|
268
|
-
|
|
266
|
+
|
|
267
|
+
const executeEvent = (e) => {
|
|
268
|
+
try {
|
|
269
|
+
const eventContext = { ...context, e };
|
|
270
|
+
evaluation(eventContext, attr.value);
|
|
271
|
+
} catch (error) {
|
|
272
|
+
__pawaDev.setError({ el: el, msg: error.message, stack: error.stack, directives: 'on-event' });
|
|
273
|
+
}
|
|
269
274
|
};
|
|
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
275
|
|
|
281
276
|
const handler = (e) => {
|
|
282
277
|
if (!checkCommonModifiers(e, modifiers)) return;
|
|
@@ -297,7 +292,7 @@ export const event = (el, attr, stateContext) => {
|
|
|
297
292
|
if (modifiers.has('stop')) e.stopPropagation();
|
|
298
293
|
|
|
299
294
|
// ========== EXECUTION ==========
|
|
300
|
-
processEventExecution(el, attr.name, modifiers, () =>
|
|
295
|
+
processEventExecution(el, attr.name, modifiers, () => executeEvent(e), eventType, 'on');
|
|
301
296
|
};
|
|
302
297
|
|
|
303
298
|
const options = {
|
|
@@ -481,18 +476,15 @@ export const documentEvent = (el, attr) => {
|
|
|
481
476
|
if (!eventType) return;
|
|
482
477
|
|
|
483
478
|
el.removeAttribute(attr.name)
|
|
484
|
-
|
|
485
|
-
const
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
}
|
|
493
|
-
console.error(error.message, error.stack)
|
|
494
|
-
__pawaDev.setError({msg: error.message, stack: error.stack, directives: 'out-event'})
|
|
495
|
-
}`)
|
|
479
|
+
|
|
480
|
+
const executeOutEvent = (e) => {
|
|
481
|
+
try {
|
|
482
|
+
const eventContext = { ...el._context, e, $element: el };
|
|
483
|
+
evaluation(eventContext, attr.value);
|
|
484
|
+
} catch (error) {
|
|
485
|
+
__pawaDev.setError({ msg: error.message, stack: error.stack, directives: 'out-event' });
|
|
486
|
+
}
|
|
487
|
+
};
|
|
496
488
|
|
|
497
489
|
const handler = (e) => {
|
|
498
490
|
if (!checkCommonModifiers(e, modifiers)) return;
|
|
@@ -507,7 +499,7 @@ export const documentEvent = (el, attr) => {
|
|
|
507
499
|
if (modifiers.has('stop')) e.stopPropagation();
|
|
508
500
|
|
|
509
501
|
// ========== EXECUTION ==========
|
|
510
|
-
processEventExecution(el, attr.name, modifiers, () =>
|
|
502
|
+
processEventExecution(el, attr.name, modifiers, () => executeOutEvent(e), eventType, 'out');
|
|
511
503
|
}
|
|
512
504
|
|
|
513
505
|
const options = {
|
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
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
134
|
-
|
|
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
|
|
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}`,
|