pawajs 1.4.23 → 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/CHANGELOG.md +2 -1
- package/index.js +10 -6
- package/normal/component.js +21 -5
- 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/CHANGELOG.md
CHANGED
|
@@ -9,4 +9,5 @@ CHANGELOG.md
|
|
|
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
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
|
|
12
|
+
+ version 1.4.23 fixed _context from production
|
|
13
|
+
+ version 1.4.24 - add HMR mapping
|
package/index.js
CHANGED
|
@@ -187,7 +187,8 @@ let stateContext = {
|
|
|
187
187
|
_template: '',
|
|
188
188
|
_serializedData:{},
|
|
189
189
|
_static: [],
|
|
190
|
-
_id:""
|
|
190
|
+
_id:"",
|
|
191
|
+
hmr:false
|
|
191
192
|
}
|
|
192
193
|
|
|
193
194
|
export const getCurrentContext = () => {
|
|
@@ -526,7 +527,8 @@ const createDeepProxy = (target, callback) => {
|
|
|
526
527
|
get(target, property) {
|
|
527
528
|
const value = target[property];
|
|
528
529
|
track(target, property);
|
|
529
|
-
|
|
530
|
+
// Only proxy plain objects/arrays and skip if already a proxy
|
|
531
|
+
if (typeof value === "object" && value !== null && !value._isPawaProxy) {
|
|
530
532
|
return createDeepProxy(value, callback);
|
|
531
533
|
}
|
|
532
534
|
return value;
|
|
@@ -559,6 +561,7 @@ export const setStateContext = (context) => {
|
|
|
559
561
|
stateContext._template = ''
|
|
560
562
|
stateContext._resume = false
|
|
561
563
|
stateContext._suspense=''
|
|
564
|
+
stateContext._hmr=false
|
|
562
565
|
stateContext._hook={
|
|
563
566
|
beforeMount:[],
|
|
564
567
|
reactiveEffect:[],
|
|
@@ -739,6 +742,7 @@ const stateWatch = (callback, dependencies) => {
|
|
|
739
742
|
export const restoreContext = (state_context) => {
|
|
740
743
|
stateContext = state_context._formerContext
|
|
741
744
|
}
|
|
745
|
+
export const HmrComponentMap=new Map()
|
|
742
746
|
/**
|
|
743
747
|
*
|
|
744
748
|
* @param {PawaElement|HTMLElement} el
|
|
@@ -988,7 +992,7 @@ export const render = (el, contexts = {}, notRender, isName) => {
|
|
|
988
992
|
return false
|
|
989
993
|
}
|
|
990
994
|
if (el.tagName === 'TITLE') {
|
|
991
|
-
document.title=el.textContent
|
|
995
|
+
document.title = (el.textContent || '').trim()
|
|
992
996
|
el.remove()
|
|
993
997
|
return
|
|
994
998
|
}
|
|
@@ -1029,7 +1033,7 @@ export const render = (el, contexts = {}, notRender, isName) => {
|
|
|
1029
1033
|
startsWithSet.forEach(starts => {
|
|
1030
1034
|
|
|
1031
1035
|
el._attributes.forEach(attr => {
|
|
1032
|
-
if (attr.name.startsWith(
|
|
1036
|
+
if (attr.name.startsWith(starts)) {
|
|
1033
1037
|
startAttribute = true
|
|
1034
1038
|
startObject[attr.name] = starts
|
|
1035
1039
|
}
|
|
@@ -1141,8 +1145,8 @@ export const render = (el, contexts = {}, notRender, isName) => {
|
|
|
1141
1145
|
render(child, context, number, isName)
|
|
1142
1146
|
})
|
|
1143
1147
|
el._callMount()
|
|
1144
|
-
el.
|
|
1145
|
-
|
|
1148
|
+
if (el.hasAttribute('p:c') && !el.hasAttribute('p-async')) {
|
|
1149
|
+
el._clearContext()
|
|
1146
1150
|
el.removeAttribute('p:c')
|
|
1147
1151
|
}
|
|
1148
1152
|
}
|
package/normal/component.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {propsValidator, setPawaDevError, pawaWayRemover, checkKeywordsExistence, sanitizeTemplate } from '../utils.js';
|
|
2
2
|
import {PawaElement,PawaComment} from '../pawaElement.js';
|
|
3
|
-
import {keepContext,render} from '../index.js'
|
|
3
|
+
import {keepContext,render, HmrComponentMap } from '../index.js'
|
|
4
4
|
import {createEffect} from '../reactive.js'
|
|
5
5
|
export const normal_component=(el,stateContext,setStateContext,mapsPlugin,formerStateContext,pawaContext,stateWatch)=>{
|
|
6
6
|
const compoBeforeCall=mapsPlugin.compoBeforeCall
|
|
@@ -79,6 +79,22 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
|
|
|
79
79
|
let compo
|
|
80
80
|
let awaits=false
|
|
81
81
|
let suspense=''
|
|
82
|
+
|
|
83
|
+
if (__pawaDev.tool) {
|
|
84
|
+
const id= crypto.randomUUID()
|
|
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})
|
|
87
|
+
}else{
|
|
88
|
+
HmrComponentMap.set(stateContexts.component._filePath,[{id:id,template:el._template,el:el,stateContext:stateContexts}])
|
|
89
|
+
}
|
|
90
|
+
el._setUnMount(()=>{
|
|
91
|
+
const array=HmrComponentMap.get(stateContexts.component._filePath)
|
|
92
|
+
if(array){
|
|
93
|
+
const index=array.findIndex(item => item.id === id)
|
|
94
|
+
if(index !== -1) array.splice(index,1)
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
}
|
|
82
98
|
try {
|
|
83
99
|
if(done){
|
|
84
100
|
const compoCall=component.component(app)
|
|
@@ -102,7 +118,7 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
|
|
|
102
118
|
}
|
|
103
119
|
childInsert(false)
|
|
104
120
|
Promise.resolve().then(()=>{
|
|
105
|
-
|
|
121
|
+
lifecycle()
|
|
106
122
|
|
|
107
123
|
}).finally(()=>{
|
|
108
124
|
el._clearContext()
|
|
@@ -191,8 +207,8 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
|
|
|
191
207
|
}
|
|
192
208
|
}
|
|
193
209
|
}
|
|
194
|
-
childInsert(awaits
|
|
195
|
-
const
|
|
210
|
+
childInsert(!!awaits);
|
|
211
|
+
const lifecycle=()=>{
|
|
196
212
|
Promise.resolve().then(()=>{
|
|
197
213
|
el._component?._hook?.effect.forEach((hook) => {
|
|
198
214
|
|
|
@@ -231,7 +247,7 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
|
|
|
231
247
|
})
|
|
232
248
|
}
|
|
233
249
|
if(awaits === false){
|
|
234
|
-
|
|
250
|
+
lifecycle()
|
|
235
251
|
el._clearContext()
|
|
236
252
|
}
|
|
237
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}`,
|