pawajs 1.4.38 → 1.4.40

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 (3) hide show
  1. package/index.js +51 -30
  2. package/merger/for.js +5 -18
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -244,10 +244,11 @@ export const getPawaAttributes = () => {
244
244
  let laziler
245
245
  export const lazyComponentElement=new Map()
246
246
  export const addLazyComponentElement=(element,func)=>{
247
- if (lazyComponentElement.has(element.tagName)) {
248
- lazyComponentElement.get(element.tagName).push({element:element,func})
247
+ const tagName=splitAndAdd(element.tagName)
248
+ if (lazyComponentElement.has(tagName)) {
249
+ lazyComponentElement.get(tagName).push({element:element,func})
249
250
  }else{
250
- lazyComponentElement.set(element.tagName, [{element:element,func}])
251
+ lazyComponentElement.set(tagName, [{element:element,func}])
251
252
  }
252
253
  }
253
254
  /**
@@ -286,7 +287,7 @@ export const createIntersectionObserver = (element, observeBy) => {
286
287
  const observer = new IntersectionObserver(entries => {
287
288
  entries.forEach(entry => {
288
289
  if (entry.isIntersecting) {
289
- const tagName = element.tagName;
290
+ const tagName = splitAndAdd(element.tagName);
290
291
  const lazyData = lazyComponents.get(tagName);
291
292
 
292
293
  if (!lazyData) return;
@@ -313,6 +314,7 @@ export const createIntersectionObserver = (element, observeBy) => {
313
314
  el._stateContext._hasRun = true;
314
315
  }
315
316
  }
317
+ lazyComponentElement.delete(tagName)
316
318
  observer.disconnect();
317
319
  }).catch(err => console.error(`Lazy load failed for ${tagName}:`, err));
318
320
  }
@@ -322,26 +324,36 @@ export const createIntersectionObserver = (element, observeBy) => {
322
324
  observer.observe(observeBy || element);
323
325
  return observer;
324
326
  }
325
- RegisterComponent.lazy=async(...args)=>{
327
+ RegisterComponent.lazy=(...args)=>{
326
328
  if (typeof args[0] === 'string') {
327
329
  for (let i = 0; i < args.length; i += 2) {
328
330
  const name = args[i];
329
- const component = args[i + 1];
330
- if (components.has(name.toUpperCase())) return
331
- if (typeof name === 'string' && typeof component === 'function') {
332
- if (isServer()) {
333
- lazyComponents.set(name.toUpperCase(), {name,component});
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});
331
+ const componentFunc = args[i + 1];
332
+
333
+ if (typeof componentFunc !== 'function') {
334
+ console.warn('Mismatched arguments for RegisterComponent. Expected pairs of (string|string[], function).');
335
+ break;
336
+ }
337
+
338
+ const processName =(compName) => {
339
+ if (components.has(compName.toUpperCase())) return;
340
+ if (typeof compName === 'string') {
341
+ if (isServer()) {
342
+ componentFunc();
343
+ }
344
+ lazyComponents.set(compName.toUpperCase(), { name: compName, component: componentFunc });
345
+
346
+ }
347
+ };
348
+
349
+ if (Array.isArray(name)) {
350
+ for (const compName of name) {
351
+ processName(compName);
342
352
  }
353
+ } else if (typeof name === 'string') {
354
+ processName(name);
343
355
  } else {
344
- console.warn('Mismatched arguments for RegisterComponent. Expected pairs of (string, function).');
356
+ console.warn('Mismatched arguments for RegisterComponent. Expected pairs of (string|string[], function).');
345
357
  break;
346
358
  }
347
359
  }
@@ -856,13 +868,14 @@ export const restoreContext = (state_context) => {
856
868
  stateContext = state_context._formerContext
857
869
  }
858
870
  export const HmrComponentMap=new Map()
871
+ const renderedComponentsRusumed=new Set()
859
872
  /**
860
873
  *
861
874
  * @param {PawaElement|HTMLElement} el
862
875
  * @returns null
863
876
  */
864
877
  const component = (el, resume = false, attr, notRender, stopResume) => {
865
- if (el._running) {
878
+ if (el._running || (resume && renderedComponentsRusumed.has(attr.value))) {
866
879
  return
867
880
  }
868
881
  el._running = true
@@ -870,6 +883,7 @@ const component = (el, resume = false, attr, notRender, stopResume) => {
870
883
  if (!resume) {
871
884
  if (el._lazy) {
872
885
  // pas the normal component to lazy handler
886
+ el.style.opacity=0
873
887
  addLazyComponentElement(el,()=>normal_component(el, stateContext, setStateContext, mapsPlugins, formerStateContext, pawaContext, stateWatch))
874
888
  return
875
889
  }else{
@@ -877,7 +891,7 @@ const component = (el, resume = false, attr, notRender, stopResume) => {
877
891
  }
878
892
  } else {
879
893
  stopResume.stop = true
880
- let name
894
+ let name=''
881
895
  let comment
882
896
  let endComment
883
897
  const children = []
@@ -933,12 +947,14 @@ const component = (el, resume = false, attr, notRender, stopResume) => {
933
947
  numberComponentChildren = notRender.index + children.length -1
934
948
  }
935
949
  notRender.notRender = numberComponentChildren
936
- if (lazyComponents.has(name)) {
950
+ renderedComponentsRusumed.add(attr.value)
951
+
952
+ if (lazyComponents.has(name.toUpperCase())) {
937
953
  const trackElement=document.createElement(name)
938
954
  trackElement._stateContext=el._stateContext
939
955
  addLazyComponentElement(trackElement,()=>resumer.resume_component?.(el, attr, setStateContext, mapsPlugins, formerStateContext, pawaContext, stateWatch, { comment, endComment, name, serialized, id, children }))
940
- if (!lazyComponentElement.has(name)) {
941
- createInsectObserver(trackElement,el)
956
+ if (lazyComponentElement.has(name.toUpperCase())) {
957
+ createIntersectionObserver(trackElement,el)
942
958
  }
943
959
  }else{
944
960
  resumer.resume_component?.(el, attr, setStateContext, mapsPlugins, formerStateContext, pawaContext, stateWatch, { comment, endComment, name, serialized, id, children })
@@ -1009,6 +1025,7 @@ const mainAttribute = (el, exp) => {
1009
1025
  el.setAttribute(exp.name, value);
1010
1026
  } else {
1011
1027
  if ((exp.name === 'class' || exp.name === 'style') && enter) {
1028
+ console.log('entered',enter);
1012
1029
 
1013
1030
  requestAnimationFrame(()=>{
1014
1031
  el.setAttribute(exp.name, value);
@@ -1149,11 +1166,7 @@ export const render = (el, contexts = {}, notRender, isName) => {
1149
1166
  }
1150
1167
  }
1151
1168
 
1152
- if (Array.from(el.childNodes).some(node =>
1153
- node.nodeType === Node.TEXT_NODE && node.nodeValue.includes('@{')
1154
- ) && !el._avoidPawaRender) {
1155
- textContentHandler(el, isName)
1156
- }
1169
+
1157
1170
  let startAttribute = false
1158
1171
  const startObject = {}
1159
1172
  //get startsWith plugin
@@ -1170,6 +1183,7 @@ export const render = (el, contexts = {}, notRender, isName) => {
1170
1183
  })
1171
1184
  const number = { notRender: null }
1172
1185
  const isAcomponent=el._componentName?true:false
1186
+
1173
1187
  el._attributes.forEach(attr => {
1174
1188
 
1175
1189
  if (stopResume.stop || el._hasRun) return
@@ -1191,6 +1205,8 @@ export const render = (el, contexts = {}, notRender, isName) => {
1191
1205
  }
1192
1206
  else if (attr.name.startsWith('c-c-')) {
1193
1207
  stopResume.stop = true
1208
+
1209
+
1194
1210
  component(el, true, attr, notRender, stopResume)// component continuity
1195
1211
  } else if (attr.name.startsWith('c-at-')) {
1196
1212
  resumer.resume_attribute?.(el, attr, notRender) //attribute continuity
@@ -1239,7 +1255,13 @@ export const render = (el, contexts = {}, notRender, isName) => {
1239
1255
 
1240
1256
  })
1241
1257
  }
1258
+
1242
1259
  if (stopResume.stop) return
1260
+ if (Array.from(el.childNodes).some(node =>
1261
+ node.nodeType === Node.TEXT_NODE && node.nodeValue.includes('@{')
1262
+ ) && !el._avoidPawaRender) {
1263
+ textContentHandler(el, isName)
1264
+ }
1243
1265
  if (el._componentName && !el._avoidPawaRender) {
1244
1266
  component(el)
1245
1267
  return
@@ -1336,7 +1358,6 @@ const Pawa = {
1336
1358
  useAsync,
1337
1359
  useInnerContext,
1338
1360
  RegisterComponent,
1339
- forwardProps,
1340
1361
  runEffect,
1341
1362
  html
1342
1363
  }
package/merger/for.js CHANGED
@@ -12,6 +12,7 @@ export const merger_for = (el, stateContext, attr, arrayName, arrayItem, indexes
12
12
  let context=el._context
13
13
  const keyOrder=keyOrders || new Map()
14
14
  let noKey
15
+ let array
15
16
  const evaluate = () => {
16
17
  if (endComment.parentElement === null) {
17
18
  el._deleteEffects()
@@ -20,7 +21,7 @@ export const merger_for = (el, stateContext, attr, arrayName, arrayItem, indexes
20
21
  if (!func) {
21
22
  func=el.safeEval(context, arrayName, 'for-each');
22
23
  }
23
- let array = func(...getEvalValues(context))
24
+ array = func(...getEvalValues(context))
24
25
  let update;
25
26
  if (!firstEnter) {
26
27
  const div = document.createElement('div')
@@ -56,6 +57,7 @@ export const merger_for = (el, stateContext, attr, arrayName, arrayItem, indexes
56
57
  return
57
58
  }
58
59
  if(lookLike) return
60
+
59
61
  if (lookLike === null) {
60
62
  elementArray.delete(keyComment)
61
63
 
@@ -82,7 +84,7 @@ export const merger_for = (el, stateContext, attr, arrayName, arrayItem, indexes
82
84
  let indexKey=0
83
85
  keyOrder.forEach((value,key)=>{
84
86
  if(update)return;
85
- if(div.children[indexKey]?.getAttribute('data-for-index') !== key){
87
+ if(div.children[indexKey]?.getAttribute('data-for-index') && indexKey !== key){
86
88
  update=true
87
89
  }
88
90
  indexKey++
@@ -185,22 +187,7 @@ export const merger_for = (el, stateContext, attr, arrayName, arrayItem, indexes
185
187
  stateContext._hasRun = true
186
188
  elementArray.add(keyComment)
187
189
  })
188
-
189
- } else {
190
- if(!resume)return
191
- if(once)return
192
- const number={notRender:null,index:null}
193
- elementArray.forEach((keyComment) => {
194
- if(keyComment.nextElementSibling === null) return
195
- const itemContext = {
196
- [arrayItem]: array[keyComment._index],
197
- [indexes]: keyComment._index,
198
- ...context
199
- }
200
- render(keyComment.nextElementSibling, itemContext,{notRender:false,index:null})
201
- })
202
- once=true
203
- }
190
+ }
204
191
  firstEnter = false
205
192
  } catch (error) {
206
193
  setPawaDevError({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pawajs",
3
- "version": "1.4.38",
3
+ "version": "1.4.40",
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",