pawajs 1.3.2 → 1.3.4

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
@@ -29,7 +29,7 @@ export const setErrorCALLER = (callback) => {
29
29
  const errorCaller = (message) => {
30
30
 
31
31
  }
32
- const client = !isServer()
32
+ const client = isServer() === false
33
33
  const serverInstance = getServerInstance()
34
34
  if (client) {
35
35
  window.__pawaDev = {
@@ -298,7 +298,7 @@ const setPrimaryAttibute = (...name) => {
298
298
  export const getPrimaryDirective=()=>primaryDirective
299
299
  setPrimaryAttibute('if', 'else-if', 'for', 'else','switch','case','default','case','key')
300
300
  setPawaAttributes('if', 'else-if', 'for', 'else', 'mount',
301
- 'unmount', 'forKey', 'state-', 'on-', 'out-','key')
301
+ 'unmount', 'forKey', 'state-', 'on-', 'out-','key','switch','case','default')
302
302
  export const getDependentAttribute = () => dependentPawaAttribute
303
303
  export const getPawaAttributes = () => {
304
304
  return pawaAttributes
@@ -358,7 +358,7 @@ export const RegisterComponent = (...args) => {
358
358
  * @param {Array|null|object|number} deps
359
359
  * Array - for state dependency.
360
360
  *
361
- * object- for any state used inside of the callback but under the use of element or component.
361
+ * object- for any state used inside of the callback but under the use of element or component. this is read-only state not for state updating
362
362
  *
363
363
  * Number - before mount hook.
364
364
  *
@@ -442,6 +442,7 @@ export const setContext = () => {
442
442
  setValue
443
443
  }
444
444
  } else {
445
+ console.log('setcontext')
445
446
  return serverInstance.setContext?.()
446
447
  }
447
448
 
@@ -466,6 +467,7 @@ export const useContext = (context) => {
466
467
  }
467
468
 
468
469
  } else {
470
+ console.log('usecontext')
469
471
  return serverInstance.useContext?.(context)
470
472
  }
471
473
  }
@@ -482,6 +484,7 @@ export const useInnerContext = () => {
482
484
  }
483
485
  return stateContext._elementContext
484
486
  } else {
487
+ console.log('innercontext')
485
488
  return serverInstance.useInnerContext?.()
486
489
  }
487
490
  }
@@ -960,12 +963,12 @@ const textContentHandler = (el, isName) => {
960
963
  }, el);
961
964
  };
962
965
 
963
- const template = (el, resume = false, notRender, attr) => {
966
+ const template = (el,notRender, attr) => {
964
967
  if (el._running) {
965
968
  return
966
969
  }
967
970
  el._running = true
968
- templates(el)
971
+ templates(el,notRender)
969
972
  }
970
973
 
971
974
  const directives = {
@@ -1045,7 +1048,7 @@ export const render = (el, contexts = {}, notRender, isName) => {
1045
1048
  directives[attr.name](el, attr, stateContext)
1046
1049
  } else if (attr.name.startsWith('on-')) {
1047
1050
  event(el, attr, stateContext)
1048
- } else if (attr.value.includes('@{') && !attr.name.startsWith('resume-attr')) {
1051
+ } else if (attr.value.includes('@{') && !attr.name.startsWith('c-at-')) {
1049
1052
  mainAttribute(el, attr, isName)
1050
1053
  } else if (attr.name.startsWith('state-')) {
1051
1054
  States(el, attr, getCurrentContext())
@@ -1072,7 +1075,10 @@ export const render = (el, contexts = {}, notRender, isName) => {
1072
1075
  directives['if'](el, attr, stateContext, true, notRender, stopResume)
1073
1076
  } else if (attr.name === 'c-for') {
1074
1077
  directives['for'](el, attr, stateContext, true, notRender, stopResume)
1075
- } else if (attr.name.startsWith('c-sw-')) {
1078
+ }else if (attr.name.startsWith('c-key-')) {
1079
+ directives['key'](el, attr, stateContext, true, notRender, stopResume)
1080
+ }
1081
+ else if (attr.name.startsWith('c-sw-')) {
1076
1082
  directives['switch'](el, attr, stateContext, true, notRender, stopResume)
1077
1083
  } else if (attr.name === 'c-for') {
1078
1084
  directives['for'](el, attr, stateContext, true, notRender, stopResume)
@@ -1114,7 +1120,7 @@ export const render = (el, contexts = {}, notRender, isName) => {
1114
1120
  return
1115
1121
  }
1116
1122
  if (el._elementType === 'template' && !el._avoidPawaRender) {
1117
- template(el)
1123
+ template(el,notRender)
1118
1124
  return
1119
1125
  }
1120
1126
 
@@ -1134,7 +1140,6 @@ export const render = (el, contexts = {}, notRender, isName) => {
1134
1140
  const number = { notRender: null, index: null }
1135
1141
  Array.from(el.children).forEach((child, index) => {
1136
1142
  number.index = index
1137
- if (number.notRender && index <= number.notRender) return
1138
1143
  render(child, context, number, isName)
1139
1144
  })
1140
1145
  el._callMount()
@@ -1144,6 +1149,7 @@ export const render = (el, contexts = {}, notRender, isName) => {
1144
1149
  }
1145
1150
  }
1146
1151
 
1152
+
1147
1153
  export const pawaStartApp = (app, context = {}) => {
1148
1154
  render(app, context)
1149
1155
  }
package/merger/for.js CHANGED
@@ -9,7 +9,7 @@ export const merger_for = (el, stateContext, attr, arrayName, arrayItem, indexes
9
9
  let func
10
10
  let once=false
11
11
  let promised
12
- const keyOrder= keyOrders || new Map()
12
+ const keyOrder=keyOrders || new Map()
13
13
  const evaluate = () => {
14
14
  if (endComment.parentElement === null) {
15
15
  el._deleteEffects()
@@ -71,7 +71,12 @@ export const merger_for = (el, stateContext, attr, arrayName, arrayItem, indexes
71
71
  keyOrder.delete(keyComment._index)
72
72
  const promise = new Promise(async(resolve) => {
73
73
  await pawaWayRemover(keyComment,keyComment._endComment)
74
- keyComment._deleteKey()
74
+ if (!keyComment._deleteKey){
75
+ keyComment.remove()
76
+ keyComment._endComment.remove()
77
+ }else{
78
+ keyComment._deleteKey()
79
+ }
75
80
  resolve(true)
76
81
  })
77
82
  removeElement.push(promise)
@@ -201,7 +206,6 @@ export const merger_for = (el, stateContext, attr, arrayName, arrayItem, indexes
201
206
  ...context
202
207
  }
203
208
  render(keyComment.nextElementSibling, itemContext,{notRender:false,index:null})
204
-
205
209
  })
206
210
  once=true
207
211
  }
@@ -10,6 +10,7 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
10
10
  el.replaceWith(endComment)
11
11
  endComment.parentElement.insertBefore(comment,endComment)
12
12
  el._underControl=comment
13
+ comment._endComment=endComment
13
14
  comment._componentElement=el
14
15
  comment._controlComponent=true
15
16
  const props={}
@@ -135,7 +136,7 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
135
136
  }
136
137
  const childInsert=()=>{
137
138
  el._component?._hook?.beforeMount?.forEach((bfm) => {
138
- const result= bfm()
139
+ const result= bfm(comment)
139
140
  if (typeof result === 'function') {
140
141
  el._unMountFunctions.push(result)
141
142
  }
@@ -176,7 +177,7 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
176
177
  el._component?._hook?.reactiveEffect.forEach((hook) => {
177
178
  if(hook?.done) return
178
179
  hook.done=true
179
- const effect=hook.effect()
180
+ const effect=hook.effect(comment)
180
181
  if (hook.deps?.component) {
181
182
  createEffect(() => {
182
183
  return effect()
@@ -190,7 +191,7 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
190
191
  }
191
192
  el._MountFunctions.forEach((func) => {
192
193
  func.done=true
193
- const result=func()
194
+ const result=func(comment)
194
195
  if (typeof result === 'function') {
195
196
  el._unMountFunctions.push(result)
196
197
  }
@@ -1,24 +1,27 @@
1
1
  import {render} from '../index.js'
2
- export const templates=(el)=>{
3
- const comment=document.createComment('<template>')
4
- const endComment=document.createComment('</template>')
5
- el.replaceWith(endComment)
6
- //kill the template element
7
- el._isKill=true
8
- el._kill=()=>{
9
- pawaWayRemover(comment,endComment)
10
- comment.remove(),endComment.remove();
11
- }
12
- endComment.parentElement.insertBefore(comment,endComment)
13
- el._underControl=comment
14
- let element=[]
2
+ export const templates=(el,notRender)=>{
3
+ if (el.hasAttribute('p:store')) {
4
+ return
5
+ }
6
+ const comment=document.createComment('<template>')
7
+ const endComment=document.createComment('</template>')
8
+ el.replaceWith(endComment)
9
+ //kill the template element
10
+ el._isKill=true
11
+ const isResume=el.hasAttribute('pawa-render')
12
+ el._kill=()=>{
13
+ pawaWayRemover(comment,endComment)
14
+ comment.remove(),endComment.remove();
15
+ }
16
+ endComment.parentElement.insertBefore(comment,endComment)
17
+ el._underControl=comment
18
+ let element=[]
15
19
  Array.from(el.content.children).forEach((child) => {
16
20
  endComment.parentElement.insertBefore(child,endComment)
17
21
  element.push(child)
18
22
  })
19
- const number={notRender:null,index:null}
23
+
20
24
  element.forEach(child=>{
21
- if(number.notRender)return
22
- render(child,el._context,number)
25
+ render(child,el._context,isResume?notRender:{ notRender: null, index: null })
23
26
  })
24
27
  }
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "pawajs",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
+ "type":"module",
4
5
  "description": "pawajs library (html runtime) for easily building web ui, enhancing html element, micro frontend etc ",
5
6
  "main": "index.js",
6
7
  "scripts": {
package/power.js CHANGED
@@ -235,7 +235,7 @@ export const For = (el, attr, stateContext,resume=false,notRender,stopResume) =>
235
235
  stopResume.stop=true
236
236
  let comment
237
237
  let endComment
238
- let dataComment
238
+ let dataElement
239
239
  let id=attr.value
240
240
  const children=[]
241
241
  const setComment=(c)=>comment=c
@@ -244,14 +244,15 @@ export const For = (el, attr, stateContext,resume=false,notRender,stopResume) =>
244
244
  getEndComment(comment,setEndComment,id,children,'isFor')
245
245
  const numberIfChildren=notRender.index + children.length - 1
246
246
  notRender.notRender=numberIfChildren
247
- dataComment=comment.nextSibling
247
+ dataElement=comment.nextSibling
248
248
  el.removeAttribute(attr.name)
249
- dataComment.remove()
250
- resumer.resume_for?.(el,attr,stateContext,{comment,endComment,id,children,dataComment})
249
+ dataElement.remove()
250
+ resumer.resume_for?.(el,attr,stateContext,{comment,endComment,id,children,dataElement})
251
251
  }
252
252
 
253
253
  }
254
254
 
255
+
255
256
  export const ref = (el, attr) => {
256
257
  el._checkStatic()
257
258
  if (el._running || checkKeywordsExistence(el._staticContext,attr.value)) {
package/server.js CHANGED
@@ -12,10 +12,11 @@ const serverInstance={
12
12
  }
13
13
  export const getServerInstance=()=>serverInstance
14
14
  export const setServer=(obj={})=>{
15
- server=true
16
15
  for (const [key,value] of Object.entries(obj)) {
16
+ console.log(key,'is start')
17
17
  if (serverInstance[key] === null) {
18
18
  serverInstance[key]=value
19
+ console.log(serverInstance[key])
19
20
  }
20
21
  }
21
22
  }