pawajs 1.4.34 → 1.4.35

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 CHANGED
@@ -275,53 +275,42 @@ export const RegisterComponent = (...args) => {
275
275
  }
276
276
  });
277
277
  }
278
- export const createInsectObserver=(element,observeBy)=>{
279
- // console.log(element,lazyComponentElement);
280
-
281
- const insectObserver=new IntersectionObserver(ob=>{
282
- const entry=ob[0]
283
- if (entry.intersectionRect.y > 0) {
284
- console.log(entry.isVisible,entry.isIntersecting,entry);
285
-
286
- }
287
- if (entry.isIntersecting) {
288
-
289
- const allThisSame=lazyComponentElement.get(element.tagName)
290
- const lazyCompo=lazyComponents.get(element.tagName)
291
- lazyCompo.component().then(res =>{
292
- if (res[lazyCompo.name]) {
293
- components.set(element.tagName, res[lazyCompo.name])
294
- lazyComponents.delete(lazyCompo.name)
295
- const compo=res[lazyCompo.name]
296
- for (const {element:el,func} of allThisSame) {
297
- if (el) {
298
- console.log(el);
299
-
300
- if (el._component) {
301
- el._component.component=compo
302
- }
303
- keepContext(el._stateContext)
304
- el._stateContext._hasRun=false
305
- func()
306
- el._stateContext._hasRun=true
307
- }
278
+ export const createIntersectionObserver = (element, observeBy) => {
279
+ const observer = new IntersectionObserver(entries => {
280
+ entries.forEach(entry => {
281
+ if (entry.isIntersecting) {
282
+ const tagName = element.tagName;
283
+ const lazyData = lazyComponents.get(tagName);
308
284
 
309
- }
310
- insectObserver.disconnect()
311
- intersectionObserver.disconnect();
312
-
285
+ if (!lazyData) return;
286
+
287
+ lazyData.component().then(res => {
288
+ const compoFunc = res[lazyData.name];
289
+ if (!compoFunc) return;
290
+
291
+ components.set(tagName, compoFunc);
292
+ lazyComponents.delete(tagName);
293
+
294
+ const instances = lazyComponentElement.get(tagName) || [];
295
+ while (instances.length > 0) {
296
+ const { element: el, func } = instances.shift();
297
+ if (el) {
298
+ if (el._component) el._component.component = compoFunc;
299
+
300
+ keepContext(el._stateContext);
301
+ el._stateContext._hasRun = false;
302
+ func();
303
+ el._stateContext._hasRun = true;
304
+ }
305
+ }
306
+ observer.disconnect();
307
+ }).catch(err => console.error(`Lazy load failed for ${tagName}:`, err));
313
308
  }
314
-
315
- }).catch(err=>{
316
- console.log(err);
317
-
318
- })
319
- }
320
- })
321
- insectObserver.observe(observeBy?observeBy:element)
322
- return insectObserver
323
- intersectionObserver.observe(observeBy?observeBy:element)
324
- return intersectionObserver
309
+ });
310
+ }, { rootMargin: '100px' });
311
+
312
+ observer.observe(observeBy || element);
313
+ return observer;
325
314
  }
326
315
  RegisterComponent.lazy=async(...args)=>{
327
316
  if (typeof args[0] === 'string') {
package/merger/for.js CHANGED
@@ -79,9 +79,10 @@ export const merger_for = (el, stateContext, attr, arrayName, arrayItem, indexes
79
79
  let indexKey=0
80
80
  keyOrder.forEach((value,key)=>{
81
81
  if(update)return;
82
- if(div.children[indexKey].getAttribute('data-for-index') !== key){
82
+ if(div.children[indexKey]?.getAttribute('data-for-index') !== key){
83
83
  update=true
84
84
  }
85
+ indexKey++
85
86
  })
86
87
  }
87
88
  const next = () => Promise.all(removeElement).then(async (res) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pawajs",
3
- "version": "1.4.34",
3
+ "version": "1.4.35",
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
@@ -1,7 +1,7 @@
1
1
  import {components,lazyComponents ,escapePawaAttribute,getPawaAttributes,getDependentAttribute,getPrimaryDirectives } from './index.js';
2
2
  import {splitAndAdd,replaceTemplateOperators,setPawaDevError,getEvalValues} from './utils.js';
3
3
  import PawaComponent from './pawaComponent.js';
4
- import { createInsectObserver } from './index.js';
4
+ import { createIntersectionObserver } from './index.js';
5
5
  import { addLazyComponentElement } from './index.js';
6
6
  import { lazyComponentElement } from './index.js';
7
7
 
@@ -54,7 +54,7 @@ export class PawaElement {
54
54
  if (lazyComponents.has(this._el.tagName)) {
55
55
  this._lazy=true
56
56
  if (!lazyComponentElement.has(this._el.tagName)) {
57
- createInsectObserver(this._el)
57
+ createIntersectionObserver(this._el)
58
58
  }
59
59
  }
60
60
  }