pawajs 2.0.7 → 2.0.8
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/package.json +1 -1
- package/pawaElement.js +26 -41
package/package.json
CHANGED
package/pawaElement.js
CHANGED
|
@@ -10,7 +10,6 @@ import { lazyComponentElement } from './index.js';
|
|
|
10
10
|
export class PawaElement {
|
|
11
11
|
|
|
12
12
|
#context
|
|
13
|
-
#el
|
|
14
13
|
/**
|
|
15
14
|
*
|
|
16
15
|
* @param {HTMLElement} element
|
|
@@ -18,24 +17,10 @@ export class PawaElement {
|
|
|
18
17
|
*/
|
|
19
18
|
constructor(element,context) {
|
|
20
19
|
this.#context=context
|
|
21
|
-
this.#el=element
|
|
22
|
-
// ── Bind every method that touches private fields ──
|
|
23
|
-
this.getChildrenTree = this.getChildrenTree.bind(this)
|
|
24
|
-
this.checkLazy = this.checkLazy.bind(this)
|
|
25
|
-
this.safeEval = this.safeEval.bind(this)
|
|
26
|
-
this.setPawaAttr = this.setPawaAttr.bind(this)
|
|
27
|
-
this.findPawaAttribute = this.findPawaAttribute.bind(this)
|
|
28
|
-
this.getNewElementByRemovingAttr = this.getNewElementByRemovingAttr.bind(this)
|
|
29
|
-
this.remove = this.remove.bind(this)
|
|
30
|
-
this.unMount = this.unMount.bind(this)
|
|
31
|
-
this.elementType = this.elementType.bind(this)
|
|
32
|
-
this.setProps = this.setProps.bind(this)
|
|
33
|
-
this.clearContext = this.clearContext.bind(this)
|
|
34
|
-
// ───────────────────────────────────────────
|
|
35
20
|
const div=element.cloneNode(true)
|
|
36
21
|
Object.assign(this, {
|
|
37
22
|
_resetEffects: new Set(), _context: context, _avoidPawaRender: element.hasAttribute('pawa-avoid'),
|
|
38
|
-
|
|
23
|
+
_el: element, _out: false, _stateContext: null, _terminateEffects: new Set(), _deleteEffects: this.terminateEffects,
|
|
39
24
|
_slots: document.createDocumentFragment(), _mainAttribute: {}, _preRenderAvoid: [], _running: false,
|
|
40
25
|
_hasForOrIf: this.hasForOrIf, _elementContent: element.textContent, _textContent: {}, _attributes: [],
|
|
41
26
|
_template: div.outerHTML, _exitAnimation: null, _component: null, _unMountFunctions: [], _MountFunctions: [],_beforeUnMountFunctions:[],
|
|
@@ -63,13 +48,13 @@ export class PawaElement {
|
|
|
63
48
|
Object.assign(element,pawa)
|
|
64
49
|
}
|
|
65
50
|
getChildrenTree(){
|
|
66
|
-
return Array.from(this
|
|
51
|
+
return Array.from(this._el.children)
|
|
67
52
|
}
|
|
68
53
|
checkLazy(){
|
|
69
|
-
if (lazyComponents.has(splitAndAdd(this
|
|
70
|
-
if(components.has(splitAndAdd(this
|
|
54
|
+
if (lazyComponents.has(splitAndAdd(this._el.tagName))) {
|
|
55
|
+
if(components.has(splitAndAdd(this._el.tagName))) return
|
|
71
56
|
this._lazy=true
|
|
72
|
-
triggerLazyLoad(splitAndAdd(this
|
|
57
|
+
triggerLazyLoad(splitAndAdd(this._el.tagName))
|
|
73
58
|
|
|
74
59
|
}
|
|
75
60
|
}
|
|
@@ -91,9 +76,9 @@ export class PawaElement {
|
|
|
91
76
|
|
|
92
77
|
}catch(error){
|
|
93
78
|
throw new Error(`Error evaluating expression: ${expression}\n${error.message}`);
|
|
94
|
-
|
|
79
|
+
|
|
95
80
|
__pawaDev.setError({
|
|
96
|
-
el:
|
|
81
|
+
el:this?._el,
|
|
97
82
|
msg:`from ${expression}`,
|
|
98
83
|
directives:directive,
|
|
99
84
|
stack:error.stack,
|
|
@@ -108,24 +93,24 @@ export class PawaElement {
|
|
|
108
93
|
})
|
|
109
94
|
}
|
|
110
95
|
setPawaAttr(){
|
|
111
|
-
const isResume=this
|
|
112
|
-
if (this
|
|
96
|
+
const isResume=this._el.hasAttribute('p:c')
|
|
97
|
+
if (this._el.hasAttribute('p-async')) return
|
|
113
98
|
if(isResume){
|
|
114
|
-
const pawaAttr=this
|
|
99
|
+
const pawaAttr=this._el.getAttribute('p:c')
|
|
115
100
|
const array=pawaAttr.split(';')
|
|
116
101
|
array.forEach(value =>{
|
|
117
|
-
if(!this
|
|
102
|
+
if(!this._el.hasAttribute(value.toLowerCase())) {
|
|
118
103
|
return
|
|
119
104
|
}
|
|
120
|
-
this._attributes.push({name:value,value:this
|
|
121
|
-
// console.log(this
|
|
105
|
+
this._attributes.push({name:value,value:this._el.getAttribute(value.toLowerCase())})
|
|
106
|
+
// console.log(this._el,this._attributes);
|
|
122
107
|
})
|
|
123
108
|
}else{
|
|
124
|
-
this._attributes=Array.from(this
|
|
109
|
+
this._attributes=Array.from(this._el.attributes)
|
|
125
110
|
}
|
|
126
111
|
}
|
|
127
112
|
findPawaAttribute(){
|
|
128
|
-
Array.from(this
|
|
113
|
+
Array.from(this._el.attributes).forEach((attr) => {
|
|
129
114
|
const pawaAttribute=getPawaAttributes()
|
|
130
115
|
const dependentAttribute=getDependentAttribute()
|
|
131
116
|
if (pawaAttribute.has(attr.name) && !dependentAttribute.has(attr.name)) {
|
|
@@ -158,7 +143,7 @@ export class PawaElement {
|
|
|
158
143
|
}
|
|
159
144
|
|
|
160
145
|
getNewElementByRemovingAttr(attrName){
|
|
161
|
-
const element=this
|
|
146
|
+
const element=this._el.cloneNode(true)
|
|
162
147
|
element.removeAttribute(attrName)
|
|
163
148
|
return element
|
|
164
149
|
}
|
|
@@ -202,7 +187,7 @@ export class PawaElement {
|
|
|
202
187
|
const animate=this._exitAnimation().then(async () => {
|
|
203
188
|
await this._callUnmount()
|
|
204
189
|
this._out = true
|
|
205
|
-
this
|
|
190
|
+
this._el.remove()
|
|
206
191
|
if (callback) {
|
|
207
192
|
callback()
|
|
208
193
|
}
|
|
@@ -214,7 +199,7 @@ export class PawaElement {
|
|
|
214
199
|
} else {
|
|
215
200
|
this._callUnmount()
|
|
216
201
|
this._out=true
|
|
217
|
-
this
|
|
202
|
+
this._el.remove()
|
|
218
203
|
if (callback) {
|
|
219
204
|
callback()
|
|
220
205
|
}
|
|
@@ -238,9 +223,9 @@ export class PawaElement {
|
|
|
238
223
|
func()
|
|
239
224
|
})
|
|
240
225
|
this._deleteEffects()
|
|
241
|
-
Array.from(this
|
|
226
|
+
Array.from(this._el.childNodes).forEach(child => {
|
|
242
227
|
if (child.nodeType === 1) {
|
|
243
|
-
if (child?.
|
|
228
|
+
if (child?._el) {
|
|
244
229
|
child._out = true
|
|
245
230
|
child._deleteEffects()
|
|
246
231
|
child._callUnmount()
|
|
@@ -269,21 +254,21 @@ export class PawaElement {
|
|
|
269
254
|
if (this._avoidPawaRender) {
|
|
270
255
|
return
|
|
271
256
|
}
|
|
272
|
-
const tag = this
|
|
257
|
+
const tag = this._el.tagName
|
|
273
258
|
try {
|
|
274
|
-
if (components.has(splitAndAdd(tag)) || this._lazy && !this
|
|
259
|
+
if (components.has(splitAndAdd(tag)) || this._lazy && !this._el.hasAttribute('data-prevent:c')) {
|
|
275
260
|
this._elementType='component'
|
|
276
261
|
this._componentOrTemplate=true
|
|
277
262
|
this._deCompositionElement=true
|
|
278
263
|
this._componentName=splitAndAdd(tag)
|
|
279
264
|
const forLazy=()=>true
|
|
280
265
|
this._component=new PawaComponent(components.get(splitAndAdd(tag)) || forLazy)
|
|
281
|
-
Array.from(this
|
|
266
|
+
Array.from(this._el.children).forEach(slot =>{
|
|
282
267
|
if (slot.tagName === 'TEMPLATE' && slot.getAttribute('prop') && !slot.hasAttribute('js')) {
|
|
283
268
|
this._slots.appendChild(slot)
|
|
284
269
|
}
|
|
285
270
|
})
|
|
286
|
-
this._componentChildren=this
|
|
271
|
+
this._componentChildren=this._el.innerHTML
|
|
287
272
|
|
|
288
273
|
} else if(tag ==='TEMPLATE'){
|
|
289
274
|
this._elementType='template'
|
|
@@ -312,9 +297,9 @@ export class PawaElement {
|
|
|
312
297
|
return
|
|
313
298
|
}
|
|
314
299
|
if (this._componentName) {
|
|
315
|
-
const hasPC=this
|
|
300
|
+
const hasPC=this._el.hasAttribute('p:c')
|
|
316
301
|
if (hasPC) {
|
|
317
|
-
Array.from(this
|
|
302
|
+
Array.from(this._el.attributes).forEach(attr => {
|
|
318
303
|
if (attr.name.startsWith('c-') || attr.name === 'by') return
|
|
319
304
|
this._attributes.push({name:attr.name,value:attr.value})
|
|
320
305
|
});
|