pawajs 1.4.32 → 1.4.33
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 +101 -5
- package/package.json +1 -1
- package/pawaElement.js +18 -5
package/CHANGELOG.md
CHANGED
|
@@ -15,4 +15,5 @@ CHANGELOG.md
|
|
|
15
15
|
+ version 1.4.27 - fixed __pawaDev Tools,
|
|
16
16
|
+ version 1.4.28 - fixed pawaElement checkStaticsContext
|
|
17
17
|
+ version 1.4.30 - removed console warn from useContext
|
|
18
|
-
+ version 1.4.31 - tried updating key to add element when server key is different
|
|
18
|
+
+ version 1.4.31- 1.4.32 - tried updating key to add element when server key is different
|
|
19
|
+
+ version 1.4.33 - added registerComponent.lazy
|
package/index.js
CHANGED
|
@@ -177,6 +177,7 @@ export const keepContext = (context) => {
|
|
|
177
177
|
|
|
178
178
|
}
|
|
179
179
|
export const components = new Map()
|
|
180
|
+
export const lazyComponents=new Map()
|
|
180
181
|
/**
|
|
181
182
|
* @type {PawaComponent}
|
|
182
183
|
*/
|
|
@@ -233,7 +234,15 @@ export const getDependentAttribute = () => dependentPawaAttribute
|
|
|
233
234
|
export const getPawaAttributes = () => {
|
|
234
235
|
return pawaAttributes
|
|
235
236
|
}
|
|
236
|
-
|
|
237
|
+
let laziler
|
|
238
|
+
export const lazyComponentElement=new Map()
|
|
239
|
+
export const addLazyComponentElement=(element,func)=>{
|
|
240
|
+
if (lazyComponentElement.has(element.tagName)) {
|
|
241
|
+
lazyComponentElement.get(element.tagName).push({element:element,func})
|
|
242
|
+
}else{
|
|
243
|
+
lazyComponentElement.set(element.tagName, [{element:element,func}])
|
|
244
|
+
}
|
|
245
|
+
}
|
|
237
246
|
/**
|
|
238
247
|
*
|
|
239
248
|
* @param {...()=>string|null} component
|
|
@@ -266,6 +275,79 @@ export const RegisterComponent = (...args) => {
|
|
|
266
275
|
}
|
|
267
276
|
});
|
|
268
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
|
+
}
|
|
308
|
+
|
|
309
|
+
}
|
|
310
|
+
insectObserver.disconnect()
|
|
311
|
+
intersectionObserver.disconnect();
|
|
312
|
+
|
|
313
|
+
}
|
|
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
|
|
325
|
+
}
|
|
326
|
+
RegisterComponent.lazy=async(...args)=>{
|
|
327
|
+
if (typeof args[0] === 'string') {
|
|
328
|
+
for (let i = 0; i < args.length; i += 2) {
|
|
329
|
+
const name = args[i];
|
|
330
|
+
const component = args[i + 1];
|
|
331
|
+
if (components.has(name.toUpperCase())) return
|
|
332
|
+
if (typeof name === 'string' && typeof component === 'function') {
|
|
333
|
+
if (isServer()) {
|
|
334
|
+
const compo=await component()
|
|
335
|
+
if (compo[name]) {
|
|
336
|
+
components.set(name.toUpperCase(),compo[name])
|
|
337
|
+
}else{
|
|
338
|
+
console.log(`component name doesn't matched the export ${name}`);
|
|
339
|
+
}
|
|
340
|
+
}else{
|
|
341
|
+
lazyComponents.set(name.toUpperCase(), {name,component});
|
|
342
|
+
}
|
|
343
|
+
} else {
|
|
344
|
+
console.warn('Mismatched arguments for RegisterComponent. Expected pairs of (string, function).');
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
269
351
|
|
|
270
352
|
/**
|
|
271
353
|
*
|
|
@@ -763,7 +845,13 @@ const component = (el, resume = false, attr, notRender, stopResume) => {
|
|
|
763
845
|
el._running = true
|
|
764
846
|
|
|
765
847
|
if (!resume) {
|
|
766
|
-
|
|
848
|
+
if (el._lazy) {
|
|
849
|
+
// pas the normal component to lazy handler
|
|
850
|
+
addLazyComponentElement(el,()=>normal_component(el, stateContext, setStateContext, mapsPlugins, formerStateContext, pawaContext, stateWatch))
|
|
851
|
+
return
|
|
852
|
+
}else{
|
|
853
|
+
normal_component(el, stateContext, setStateContext, mapsPlugins, formerStateContext, pawaContext, stateWatch)
|
|
854
|
+
}
|
|
767
855
|
} else {
|
|
768
856
|
stopResume.stop = true
|
|
769
857
|
let name
|
|
@@ -822,6 +910,14 @@ const component = (el, resume = false, attr, notRender, stopResume) => {
|
|
|
822
910
|
numberComponentChildren = notRender.index + children.length -1
|
|
823
911
|
}
|
|
824
912
|
notRender.notRender = numberComponentChildren
|
|
913
|
+
if (lazyComponents.has(name)) {
|
|
914
|
+
const trackElement=document.createElement(name)
|
|
915
|
+
trackElement._stateContext=el._stateContext
|
|
916
|
+
addLazyComponentElement(trackElement,()=>resumer.resume_component?.(el, attr, setStateContext, mapsPlugins, formerStateContext, pawaContext, stateWatch, { comment, endComment, name, serialized, id, children }))
|
|
917
|
+
if (!lazyComponentElement.has(name)) {
|
|
918
|
+
createInsectObserver(trackElement,el)
|
|
919
|
+
}
|
|
920
|
+
}
|
|
825
921
|
resumer.resume_component?.(el, attr, setStateContext, mapsPlugins, formerStateContext, pawaContext, stateWatch, { comment, endComment, name, serialized, id, children })
|
|
826
922
|
}
|
|
827
923
|
}
|
|
@@ -1077,11 +1173,11 @@ export const render = (el, contexts = {}, notRender, isName) => {
|
|
|
1077
1173
|
} else if (attr.name.startsWith('c-t')) {//text continuity
|
|
1078
1174
|
resumer.resume_text(el, attr, isName)
|
|
1079
1175
|
} else if (attr.name.startsWith('c-if-')) {
|
|
1080
|
-
directives['if'](el, attr, stateContext, true, notRender, stopResume)
|
|
1176
|
+
directives['if'](el, attr, stateContext, true, notRender, stopResume)
|
|
1081
1177
|
} else if (attr.name === 'c-for') {
|
|
1082
|
-
directives['for-each'](el, attr, stateContext, true, notRender, stopResume)
|
|
1178
|
+
directives['for-each'](el, attr, stateContext, true, notRender, stopResume)
|
|
1083
1179
|
}else if (attr.name.startsWith('c-key-')) {
|
|
1084
|
-
directives['key'](el, attr, stateContext, true, notRender, stopResume)
|
|
1180
|
+
directives['key'](el, attr, stateContext, true, notRender, stopResume)
|
|
1085
1181
|
}
|
|
1086
1182
|
else if (attr.name.startsWith('c-sw-')) {
|
|
1087
1183
|
directives['switch'](el, attr, stateContext, true, notRender, stopResume)// switch continuity
|
package/package.json
CHANGED
package/pawaElement.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import {components,escapePawaAttribute,getPawaAttributes,getDependentAttribute,getPrimaryDirectives } from './index.js';
|
|
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';
|
|
5
|
+
import { addLazyComponentElement } from './index.js';
|
|
6
|
+
import { lazyComponentElement } from './index.js';
|
|
7
|
+
|
|
4
8
|
|
|
5
9
|
|
|
6
10
|
export class PawaElement {
|
|
@@ -30,11 +34,12 @@ export class PawaElement {
|
|
|
30
34
|
_scriptDone: false, _underControl: null, safeEval: this.safeEval, _reactiveProps: {},
|
|
31
35
|
_clearContext:this.clearContext
|
|
32
36
|
})
|
|
33
|
-
|
|
37
|
+
|
|
34
38
|
if(this._avoidPawaRender) {
|
|
35
39
|
element.removeAttribute('pawa-avoid')
|
|
36
40
|
Array.from(element.children).forEach((child) => { if (child.nodeType === 1) child.setAttribute('pawa-avoid','') })
|
|
37
41
|
}
|
|
42
|
+
this.checkLazy()
|
|
38
43
|
this.setPawaAttr(); this.elementType(); this.setProps(); this.setAttri(); this.findPawaAttribute()
|
|
39
44
|
}
|
|
40
45
|
|
|
@@ -45,7 +50,14 @@ export class PawaElement {
|
|
|
45
50
|
getChildrenTree(){
|
|
46
51
|
return Array.from(this._el.children)
|
|
47
52
|
}
|
|
48
|
-
|
|
53
|
+
checkLazy(){
|
|
54
|
+
if (lazyComponents.has(this._el.tagName)) {
|
|
55
|
+
this._lazy=true
|
|
56
|
+
if (!lazyComponentElement.has(this._el.tagName)) {
|
|
57
|
+
createInsectObserver(this._el)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
49
61
|
safeEval(context,expression,directive,resolve=false){
|
|
50
62
|
try{
|
|
51
63
|
const keys = Object.keys(context);
|
|
@@ -230,12 +242,13 @@ export class PawaElement {
|
|
|
230
242
|
}
|
|
231
243
|
const tag = this._el.tagName
|
|
232
244
|
try {
|
|
233
|
-
if (components.has(splitAndAdd(tag))) {
|
|
245
|
+
if (components.has(splitAndAdd(tag)) || this._lazy) {
|
|
234
246
|
this._elementType='component'
|
|
235
247
|
this._componentOrTemplate=true
|
|
236
248
|
this._deCompositionElement=true
|
|
237
249
|
this._componentName=splitAndAdd(tag)
|
|
238
|
-
|
|
250
|
+
const forLazy=()=>true
|
|
251
|
+
this._component=new PawaComponent(components.get(splitAndAdd(tag)) || forLazy)
|
|
239
252
|
Array.from(this._el.children).forEach(slot =>{
|
|
240
253
|
if (slot.tagName === 'TEMPLATE' && slot.getAttribute('prop') && !slot.hasAttribute('js')) {
|
|
241
254
|
this._slots.appendChild(slot)
|