pawajs 2.0.6 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/pawaElement.js +26 -28
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pawajs",
3
- "version": "2.0.6",
3
+ "version": "2.0.8",
4
4
  "type":"module",
5
5
  "description": "pawajs library (reactive web runtime) for easily building web ui, enhancing html element, micro frontend, spa etc ",
6
6
  "main": "index.js",
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,11 +17,10 @@ export class PawaElement {
18
17
  */
19
18
  constructor(element,context) {
20
19
  this.#context=context
21
- this.#el=element
22
20
  const div=element.cloneNode(true)
23
21
  Object.assign(this, {
24
22
  _resetEffects: new Set(), _context: context, _avoidPawaRender: element.hasAttribute('pawa-avoid'),
25
- _out: false, _stateContext: null, _terminateEffects: new Set(), _deleteEffects: this.terminateEffects,
23
+ _el: element, _out: false, _stateContext: null, _terminateEffects: new Set(), _deleteEffects: this.terminateEffects,
26
24
  _slots: document.createDocumentFragment(), _mainAttribute: {}, _preRenderAvoid: [], _running: false,
27
25
  _hasForOrIf: this.hasForOrIf, _elementContent: element.textContent, _textContent: {}, _attributes: [],
28
26
  _template: div.outerHTML, _exitAnimation: null, _component: null, _unMountFunctions: [], _MountFunctions: [],_beforeUnMountFunctions:[],
@@ -50,13 +48,13 @@ export class PawaElement {
50
48
  Object.assign(element,pawa)
51
49
  }
52
50
  getChildrenTree(){
53
- return Array.from(this.#el.children)
51
+ return Array.from(this._el.children)
54
52
  }
55
53
  checkLazy(){
56
- if (lazyComponents.has(splitAndAdd(this.#el.tagName))) {
57
- if(components.has(splitAndAdd(this.#el.tagName))) return
54
+ if (lazyComponents.has(splitAndAdd(this._el.tagName))) {
55
+ if(components.has(splitAndAdd(this._el.tagName))) return
58
56
  this._lazy=true
59
- triggerLazyLoad(splitAndAdd(this.#el.tagName))
57
+ triggerLazyLoad(splitAndAdd(this._el.tagName))
60
58
 
61
59
  }
62
60
  }
@@ -78,9 +76,9 @@ export class PawaElement {
78
76
 
79
77
  }catch(error){
80
78
  throw new Error(`Error evaluating expression: ${expression}\n${error.message}`);
81
- let element=this.#el || null
79
+
82
80
  __pawaDev.setError({
83
- el:element,
81
+ el:this?._el,
84
82
  msg:`from ${expression}`,
85
83
  directives:directive,
86
84
  stack:error.stack,
@@ -95,24 +93,24 @@ export class PawaElement {
95
93
  })
96
94
  }
97
95
  setPawaAttr(){
98
- const isResume=this.#el.hasAttribute('p:c')
99
- if (this.#el.hasAttribute('p-async')) return
96
+ const isResume=this._el.hasAttribute('p:c')
97
+ if (this._el.hasAttribute('p-async')) return
100
98
  if(isResume){
101
- const pawaAttr=this.#el.getAttribute('p:c')
99
+ const pawaAttr=this._el.getAttribute('p:c')
102
100
  const array=pawaAttr.split(';')
103
101
  array.forEach(value =>{
104
- if(!this.#el.hasAttribute(value.toLowerCase())) {
102
+ if(!this._el.hasAttribute(value.toLowerCase())) {
105
103
  return
106
104
  }
107
- this._attributes.push({name:value,value:this.#el.getAttribute(value.toLowerCase())})
108
- // console.log(this.#el,this._attributes);
105
+ this._attributes.push({name:value,value:this._el.getAttribute(value.toLowerCase())})
106
+ // console.log(this._el,this._attributes);
109
107
  })
110
108
  }else{
111
- this._attributes=Array.from(this.#el.attributes)
109
+ this._attributes=Array.from(this._el.attributes)
112
110
  }
113
111
  }
114
112
  findPawaAttribute(){
115
- Array.from(this.#el.attributes).forEach((attr) => {
113
+ Array.from(this._el.attributes).forEach((attr) => {
116
114
  const pawaAttribute=getPawaAttributes()
117
115
  const dependentAttribute=getDependentAttribute()
118
116
  if (pawaAttribute.has(attr.name) && !dependentAttribute.has(attr.name)) {
@@ -145,7 +143,7 @@ export class PawaElement {
145
143
  }
146
144
 
147
145
  getNewElementByRemovingAttr(attrName){
148
- const element=this.#el.cloneNode(true)
146
+ const element=this._el.cloneNode(true)
149
147
  element.removeAttribute(attrName)
150
148
  return element
151
149
  }
@@ -189,7 +187,7 @@ export class PawaElement {
189
187
  const animate=this._exitAnimation().then(async () => {
190
188
  await this._callUnmount()
191
189
  this._out = true
192
- this.#el.remove()
190
+ this._el.remove()
193
191
  if (callback) {
194
192
  callback()
195
193
  }
@@ -201,7 +199,7 @@ export class PawaElement {
201
199
  } else {
202
200
  this._callUnmount()
203
201
  this._out=true
204
- this.#el.remove()
202
+ this._el.remove()
205
203
  if (callback) {
206
204
  callback()
207
205
  }
@@ -225,9 +223,9 @@ export class PawaElement {
225
223
  func()
226
224
  })
227
225
  this._deleteEffects()
228
- Array.from(this.#el.childNodes).forEach(child => {
226
+ Array.from(this._el.childNodes).forEach(child => {
229
227
  if (child.nodeType === 1) {
230
- if (child?._template) {
228
+ if (child?._el) {
231
229
  child._out = true
232
230
  child._deleteEffects()
233
231
  child._callUnmount()
@@ -256,21 +254,21 @@ export class PawaElement {
256
254
  if (this._avoidPawaRender) {
257
255
  return
258
256
  }
259
- const tag = this.#el.tagName
257
+ const tag = this._el.tagName
260
258
  try {
261
- if (components.has(splitAndAdd(tag)) || this._lazy && !this.#el.hasAttribute('data-prevent:c')) {
259
+ if (components.has(splitAndAdd(tag)) || this._lazy && !this._el.hasAttribute('data-prevent:c')) {
262
260
  this._elementType='component'
263
261
  this._componentOrTemplate=true
264
262
  this._deCompositionElement=true
265
263
  this._componentName=splitAndAdd(tag)
266
264
  const forLazy=()=>true
267
265
  this._component=new PawaComponent(components.get(splitAndAdd(tag)) || forLazy)
268
- Array.from(this.#el.children).forEach(slot =>{
266
+ Array.from(this._el.children).forEach(slot =>{
269
267
  if (slot.tagName === 'TEMPLATE' && slot.getAttribute('prop') && !slot.hasAttribute('js')) {
270
268
  this._slots.appendChild(slot)
271
269
  }
272
270
  })
273
- this._componentChildren=this.#el.innerHTML
271
+ this._componentChildren=this._el.innerHTML
274
272
 
275
273
  } else if(tag ==='TEMPLATE'){
276
274
  this._elementType='template'
@@ -299,9 +297,9 @@ export class PawaElement {
299
297
  return
300
298
  }
301
299
  if (this._componentName) {
302
- const hasPC=this.#el.hasAttribute('p:c')
300
+ const hasPC=this._el.hasAttribute('p:c')
303
301
  if (hasPC) {
304
- Array.from(this.#el.attributes).forEach(attr => {
302
+ Array.from(this._el.attributes).forEach(attr => {
305
303
  if (attr.name.startsWith('c-') || attr.name === 'by') return
306
304
  this._attributes.push({name:attr.name,value:attr.value})
307
305
  });