pawajs 1.4.34 → 1.4.36
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 +50 -46
- package/merger/for.js +2 -1
- package/package.json +1 -1
- package/pawaElement.js +4 -4
- package/power.js +1 -1
- package/utils.js +6 -1
package/index.js
CHANGED
|
@@ -275,53 +275,42 @@ export const RegisterComponent = (...args) => {
|
|
|
275
275
|
}
|
|
276
276
|
});
|
|
277
277
|
}
|
|
278
|
-
export const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
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
|
-
|
|
311
|
-
|
|
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
|
-
|
|
316
|
-
|
|
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') {
|
|
@@ -331,6 +320,7 @@ RegisterComponent.lazy=async(...args)=>{
|
|
|
331
320
|
if (components.has(name.toUpperCase())) return
|
|
332
321
|
if (typeof name === 'string' && typeof component === 'function') {
|
|
333
322
|
if (isServer()) {
|
|
323
|
+
lazyComponents.set(name.toUpperCase(), {name,component});
|
|
334
324
|
const compo=await component()
|
|
335
325
|
if (compo[name]) {
|
|
336
326
|
components.set(name.toUpperCase(),compo[name])
|
|
@@ -613,6 +603,20 @@ export const useInsert = (obj = {}) => {
|
|
|
613
603
|
}
|
|
614
604
|
}
|
|
615
605
|
const createDeepProxy = (target, callback) => {
|
|
606
|
+
// Skip proxies for DOM objects and native objects that don't work well with proxies
|
|
607
|
+
if (target instanceof FileList) return target
|
|
608
|
+
if (target instanceof File) return target
|
|
609
|
+
if (target instanceof Blob) return target
|
|
610
|
+
if (target instanceof FormData) return target
|
|
611
|
+
if (target instanceof Date) return target
|
|
612
|
+
if (target instanceof RegExp) return target
|
|
613
|
+
|
|
614
|
+
// Also skip if it's already a proxy
|
|
615
|
+
if (target && target._isPawaProxy) return target
|
|
616
|
+
|
|
617
|
+
// Also skip if it's a DOM element
|
|
618
|
+
if (target && target.nodeType && typeof target === 'object') return target
|
|
619
|
+
|
|
616
620
|
return new Proxy(target, {
|
|
617
621
|
get(target, property) {
|
|
618
622
|
const value = target[property];
|
|
@@ -1078,7 +1082,7 @@ const directives = {
|
|
|
1078
1082
|
'for-each': For,
|
|
1079
1083
|
else:(el)=>{el._running =true},
|
|
1080
1084
|
case:(el)=>{el._running =true},
|
|
1081
|
-
default:(el)=>{el._running =true},
|
|
1085
|
+
"s-default":(el)=>{el._running =true},
|
|
1082
1086
|
'else-if':(el)=>{el._running =true},
|
|
1083
1087
|
mount: mountElement,
|
|
1084
1088
|
unmount: unMountElement,
|
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]
|
|
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
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 {
|
|
4
|
+
import { createIntersectionObserver } from './index.js';
|
|
5
5
|
import { addLazyComponentElement } from './index.js';
|
|
6
6
|
import { lazyComponentElement } from './index.js';
|
|
7
7
|
|
|
@@ -51,10 +51,10 @@ export class PawaElement {
|
|
|
51
51
|
return Array.from(this._el.children)
|
|
52
52
|
}
|
|
53
53
|
checkLazy(){
|
|
54
|
-
if (lazyComponents.has(this._el.tagName)) {
|
|
54
|
+
if (lazyComponents.has(splitAndAdd(this._el.tagName))) {
|
|
55
55
|
this._lazy=true
|
|
56
|
-
if (!lazyComponentElement.has(this._el.tagName)) {
|
|
57
|
-
|
|
56
|
+
if (!lazyComponentElement.has(splitAndAdd(this._el.tagName))) {
|
|
57
|
+
createIntersectionObserver(this._el)
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
}
|
package/power.js
CHANGED
|
@@ -222,7 +222,7 @@ export const Switch = (el, attr, stateContext,resume=false,notRender,stopResume)
|
|
|
222
222
|
chainMap.set(nextSibling.getAttribute('case'),{condition:'case',element:nextSibling})
|
|
223
223
|
getChained(nextSibling.nextElementSibling)
|
|
224
224
|
nextSibling.remove()
|
|
225
|
-
}else if (nextSibling.getAttribute('default') === '') {
|
|
225
|
+
}else if (nextSibling.getAttribute('s-default') === '') {
|
|
226
226
|
chained.push({
|
|
227
227
|
exp:'false',
|
|
228
228
|
condition:'default',
|
package/utils.js
CHANGED
|
@@ -176,7 +176,12 @@ export const sanitizeTemplate = (temp) => {
|
|
|
176
176
|
};
|
|
177
177
|
|
|
178
178
|
export const ComponentProps=(somes,message,name,key)=>{
|
|
179
|
-
let some
|
|
179
|
+
let some
|
|
180
|
+
if (typeof somes === 'function') {
|
|
181
|
+
some=somes()
|
|
182
|
+
}else{
|
|
183
|
+
some=somes
|
|
184
|
+
}
|
|
180
185
|
return({
|
|
181
186
|
Array:()=>{
|
|
182
187
|
|