pawajs 1.3.1 → 1.3.3

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
@@ -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
  *
@@ -960,12 +960,12 @@ const textContentHandler = (el, isName) => {
960
960
  }, el);
961
961
  };
962
962
 
963
- const template = (el, resume = false, notRender, attr) => {
963
+ const template = (el,notRender, attr) => {
964
964
  if (el._running) {
965
965
  return
966
966
  }
967
967
  el._running = true
968
- templates(el)
968
+ templates(el,notRender)
969
969
  }
970
970
 
971
971
  const directives = {
@@ -1045,7 +1045,7 @@ export const render = (el, contexts = {}, notRender, isName) => {
1045
1045
  directives[attr.name](el, attr, stateContext)
1046
1046
  } else if (attr.name.startsWith('on-')) {
1047
1047
  event(el, attr, stateContext)
1048
- } else if (attr.value.includes('@{') && !attr.name.startsWith('resume-attr')) {
1048
+ } else if (attr.value.includes('@{') && !attr.name.startsWith('c-at-')) {
1049
1049
  mainAttribute(el, attr, isName)
1050
1050
  } else if (attr.name.startsWith('state-')) {
1051
1051
  States(el, attr, getCurrentContext())
@@ -1072,7 +1072,10 @@ export const render = (el, contexts = {}, notRender, isName) => {
1072
1072
  directives['if'](el, attr, stateContext, true, notRender, stopResume)
1073
1073
  } else if (attr.name === 'c-for') {
1074
1074
  directives['for'](el, attr, stateContext, true, notRender, stopResume)
1075
- } else if (attr.name.startsWith('c-sw-')) {
1075
+ }else if (attr.name.startsWith('c-key-')) {
1076
+ directives['key'](el, attr, stateContext, true, notRender, stopResume)
1077
+ }
1078
+ else if (attr.name.startsWith('c-sw-')) {
1076
1079
  directives['switch'](el, attr, stateContext, true, notRender, stopResume)
1077
1080
  } else if (attr.name === 'c-for') {
1078
1081
  directives['for'](el, attr, stateContext, true, notRender, stopResume)
@@ -1114,7 +1117,7 @@ export const render = (el, contexts = {}, notRender, isName) => {
1114
1117
  return
1115
1118
  }
1116
1119
  if (el._elementType === 'template' && !el._avoidPawaRender) {
1117
- template(el)
1120
+ template(el,notRender)
1118
1121
  return
1119
1122
  }
1120
1123
 
@@ -1134,7 +1137,6 @@ export const render = (el, contexts = {}, notRender, isName) => {
1134
1137
  const number = { notRender: null, index: null }
1135
1138
  Array.from(el.children).forEach((child, index) => {
1136
1139
  number.index = index
1137
- if (number.notRender && index <= number.notRender) return
1138
1140
  render(child, context, number, isName)
1139
1141
  })
1140
1142
  el._callMount()
@@ -1144,6 +1146,7 @@ export const render = (el, contexts = {}, notRender, isName) => {
1144
1146
  }
1145
1147
  }
1146
1148
 
1149
+
1147
1150
  export const pawaStartApp = (app, context = {}) => {
1148
1151
  render(app, context)
1149
1152
  }
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,6 @@
1
1
  {
2
2
  "name": "pawajs",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "pawajs library (html runtime) for easily building web ui, enhancing html element, micro frontend etc ",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/pawaElement.js CHANGED
@@ -1,7 +1,6 @@
1
- import {components,escapePawaAttribute,getPawaAttributes,getDependentAttribute,} from './index.js';
1
+ import {components,escapePawaAttribute,getPawaAttributes,getDependentAttribute} from './index.js';
2
2
  import {splitAndAdd,replaceTemplateOperators,setPawaDevError,getEvalValues,safeEval} from './utils.js';
3
3
  import PawaComponent from './pawaComponent.js';
4
- import { getPrimaryDirective } from './index.js';
5
4
 
6
5
 
7
6
  export class PawaElement {
@@ -88,6 +87,7 @@ export class PawaElement {
88
87
  }
89
88
  })
90
89
  }
90
+ this.setPawaAttr()
91
91
  this.elementType()
92
92
  this.setProps()
93
93
  this.setAttri()
@@ -106,6 +106,19 @@ export class PawaElement {
106
106
  call()
107
107
  })
108
108
  }
109
+ setPawaAttr(){
110
+ const isResume=this._el.hasAttribute('p:c')
111
+ if(isResume){
112
+ const pawaAttr=this._el.getAttribute('p:c')
113
+ const array=pawaAttr.split(';')
114
+ array.forEach(value =>{
115
+ if(!this._el.hasAttribute(value)) return
116
+ this._attributes.push({name:value,value:this._el.getAttribute(value)})
117
+ })
118
+ }else{
119
+ this._attributes=Array.from(this._el.attributes)
120
+ }
121
+ }
109
122
  findPawaAttribute(){
110
123
  Array.from(this._el.attributes).forEach((attr) => {
111
124
  const pawaAttribute=getPawaAttributes()
@@ -198,8 +211,7 @@ export class PawaElement {
198
211
  this._out=true
199
212
  this._el.remove()
200
213
  if (callback) {
201
- console.log(callback)
202
- callback?.()
214
+ callback()
203
215
  }
204
216
  return true
205
217
  }
@@ -352,7 +364,7 @@ export class PawaComment {
352
364
  this._endComment=null
353
365
  this._keyRemover=this.keyRemoveElement
354
366
  this._resetForKeyElement=this.forKeyResetElement
355
- this._deleteKey=this.deleteKey
367
+ this._deletKey=this.deleteKey
356
368
  }
357
369
  static Element(element){
358
370
  const pawa=new PawaComment(element)
@@ -378,15 +390,15 @@ export class PawaComment {
378
390
  return
379
391
  } else {
380
392
  if (comment?.nextSibling?.nodeType === 8) {
393
+ // console.log(comment)
381
394
  if(comment.nextSibling?._controlComponent){
382
395
  comment.nextSibling._remove()
383
- }else{
396
+ }else{
384
397
  comment.nextSibling.remove()
385
398
  }
386
399
 
387
400
  } else if (comment.nextSibling.nodeType === 1) {
388
401
  if (firstElement) {
389
- console.log(callback)
390
402
  await comment.nextSibling._remove(callback)
391
403
  } else{
392
404
  await comment.nextSibling._remove()
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)) {