pawajs 1.4.6 → 1.4.8

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 CHANGED
@@ -2,3 +2,4 @@ CHANGELOG.md
2
2
  + version 1.3.0 - v1.4.0 on experiment
3
3
  + version 1.4.0 for-key bug fixing
4
4
  + version 1.4.4 added onSuspense and fix out- (document event)
5
+ + version 1.4.7 solving resuming issue when wrapping with template
package/README.md CHANGED
@@ -7,6 +7,8 @@ pawajs - power the web (reactivity and html runtime)
7
7
 
8
8
  PawaJS is a JavaScript library designed for building dynamic user interfaces. It combines a component-based architecture and progressive enhancement with a powerful reactivity system no v-dom. Its intuitive, directive-based templating feels familiar and makes it easy to create interactive applications, from simple widgets to complex single-page apps. With built-in support for server-side rendering, PawaJS is equipped for performance and scalability.
9
9
 
10
+ 🌐 **Website:** [pawajs.vercel.app](https://pawajs.vercel.app)
11
+
10
12
  ---
11
13
 
12
14
  ## Features
@@ -340,6 +342,7 @@ useValidateComponent(TodoList, {
340
342
  - `pawaStartApp(rootElement, initialContext)`: Initializes the PawaJS application on a given root DOM element.
341
343
  - `RegisterComponent(...components)`: Registers one or more components to be used in templates.
342
344
  - `$state(initialValue, localStorageKey?)`: Creates a new reactive state object.
345
+ - `PluginSystem(plugin)`: Registers a plugin to extend PawaJS functionality (e.g., Routers, Global Stores).
343
346
  - `html`: A tagged template literal for syntax highlighting and potential future optimizations.
344
347
 
345
348
  ### Component Hooks
package/index.js CHANGED
@@ -592,12 +592,7 @@ export const useAsync = () => {
592
592
  }
593
593
  } else {
594
594
  //sets server initialization to default
595
- return {
596
- $async: (callback) => {
597
- return callback()
598
- },
599
- onSuspense:(html)=>{}
600
- }
595
+ return serverInstance.useAsync?.()
601
596
  }
602
597
  }
603
598
  //resume state during after ssr
@@ -899,7 +894,7 @@ const component = (el, resume = false, attr, notRender, stopResume) => {
899
894
  getComment(el)
900
895
  getEndComment(comment)
901
896
  el.removeAttribute(attr.name)
902
- const numberComponentChildren = notRender.index + children.length - 2
897
+ const numberComponentChildren = notRender.index + children.length - 1
903
898
  notRender.notRender = numberComponentChildren
904
899
  resumer.resume_component?.(el, attr, setStateContext, mapsPlugins, formerStateContext, pawaContext, stateWatch, { comment, endComment, name, serialized, id, children })
905
900
  }
@@ -1093,7 +1088,8 @@ export const render = (el, contexts = {}, notRender, isName) => {
1093
1088
  }
1094
1089
  }
1095
1090
  PawaElement.Element(el, context)
1096
- el._staticContext = stateContext._static
1091
+ el._staticContext = stateContext?._static
1092
+ el._stateContext=stateContext
1097
1093
  for (const fn of renderAfterPawa) {
1098
1094
  try {
1099
1095
  fn(el)
@@ -1222,13 +1218,35 @@ export const render = (el, contexts = {}, notRender, isName) => {
1222
1218
  render(child, context, number, isName)
1223
1219
  })
1224
1220
  el._callMount()
1225
- if (el.hasAttribute('p:c')) {
1221
+ if (el.hasAttribute('p:c') && !el.hasAttribute('p-async')) {
1226
1222
  el.removeAttribute('p:c')
1227
1223
  }
1228
1224
  }
1229
1225
  }
1230
-
1231
-
1226
+ // added streaming awareness
1227
+ if (typeof window !== 'undefined') {
1228
+ window.__pawaStream=(element,context,statecontext)=>{
1229
+ let appContext
1230
+ if(!window?.__pawaHasStarted){
1231
+ if(window?.__startClient === null )return
1232
+ window?.__startClient()
1233
+
1234
+ window.__startClient=null
1235
+ window.__pawaHasStarted=true
1236
+ return
1237
+ }
1238
+ if(statecontext === undefined){
1239
+ appContext=stateContext
1240
+ }else{
1241
+ appContext=statecontext
1242
+ }
1243
+ keepContext(appContext)
1244
+ appContext._hasRun=false
1245
+ render(element,context,{index:0,notRender:null})
1246
+ appContext._hasRun=true
1247
+ }
1248
+
1249
+ }
1232
1250
  export const pawaStartApp = (app, context = {}) => {
1233
1251
  render(app, context)
1234
1252
  }
@@ -101,7 +101,9 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
101
101
  Object.assign(el._context,storeContext._insert)
102
102
  }
103
103
  childInsert(false)
104
- lifeCircle()
104
+ Promise.resolve().then(()=>{
105
+ lifeCircle()
106
+ })
105
107
  storeContext._hasRun=true
106
108
  stateContext=null
107
109
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pawajs",
3
- "version": "1.4.6",
3
+ "version": "1.4.8",
4
4
  "type":"module",
5
5
  "description": "pawajs library (html runtime) for easily building web ui, enhancing html element, micro frontend etc ",
6
6
  "main": "index.js",
package/pawaElement.js CHANGED
@@ -21,6 +21,7 @@ export class PawaElement {
21
21
  this._avoidPawaRender=element.hasAttribute('pawa-avoid');
22
22
  this._el=element
23
23
  this._out=false;
24
+ this._stateContext=null
24
25
  this._terminateEffects=new Set()
25
26
  this._deleteEffects=this.terminateEffects
26
27
  /**
@@ -136,6 +137,7 @@ export class PawaElement {
136
137
  }
137
138
  setPawaAttr(){
138
139
  const isResume=this._el.hasAttribute('p:c')
140
+ if (this._el.hasAttribute('p-async')) return
139
141
  if(isResume){
140
142
  const pawaAttr=this._el.getAttribute('p:c')
141
143
  const array=pawaAttr.split(';')
@@ -347,7 +349,11 @@ export class PawaElement {
347
349
  }`
348
350
  const value=this.safeEval(this._context,expression,`prop sdvd :${propsName}`,true)
349
351
  if (value) {
350
- this._props[propsName]=value
352
+ let name=propsName
353
+ if(name.includes('-')){
354
+ name=name.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
355
+ }
356
+ this._props[name]=value
351
357
  }
352
358
  }
353
359
  })
package/power.js CHANGED
@@ -63,7 +63,7 @@ export const If = (el, attr, stateContext,resume=false,notRender,stopResume) =>
63
63
  const setEndComment=(c)=>endComment=c
64
64
  getComment(el,setComment,id)
65
65
  getEndComment(comment,setEndComment,id,children)
66
- const numberIfChildren=notRender.index + children.length - 1
66
+ const numberIfChildren=notRender.index + children.length - 2
67
67
  notRender.notRender=numberIfChildren
68
68
  resumer.resume_if?.(el,attr,stateContext,{comment,endComment,id,children})
69
69
 
@@ -126,7 +126,7 @@ export const Switch = (el, attr, stateContext,resume=false,notRender,stopResume)
126
126
  const setEndComment=(c)=>endComment=c
127
127
  getComment(el,setComment,id)
128
128
  getEndComment(comment,setEndComment,id,children)
129
- const numberIfChildren=notRender.index + children.length - 1
129
+ const numberIfChildren=notRender.index + children.length - 2
130
130
  notRender.notRender=numberIfChildren
131
131
  resumer.resume_switch?.(el,attr,stateContext,{comment,endComment,id,children})
132
132
 
package/server.js CHANGED
@@ -9,6 +9,7 @@ const serverInstance={
9
9
  $state:null,
10
10
  accessChild:null,
11
11
  useServer:null,
12
+ useAsync:null,
12
13
  }
13
14
  export const getServerInstance=()=>serverInstance
14
15
  export const setServer=(obj={})=>{