pawajs 2.0.8 → 2.0.9

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/cdn/index.html ADDED
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
3
+ <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
4
+ <!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
5
+ <!--[if gt IE 8]> <html class="no-js"> <!--<![endif]-->
6
+ <html>
7
+ <head>
8
+ <meta charset="utf-8">
9
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
10
+ <title>pawajs</title>
11
+ <meta name="description" content="">
12
+ <meta name="viewport" content="width=device-width, initial-scale=1">
13
+ <link rel="stylesheet" href="">
14
+ </head>
15
+ <body>
16
+ <!--[if lt IE 7]>
17
+ <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="#">upgrade your browser</a> to improve your experience.</p>
18
+ <![endif]-->
19
+ <div id="app">
20
+ <counter></counter>
21
+ </div>
22
+
23
+ <script src="./index.js" type="module"></script>
24
+ </body>
25
+ </html>
package/cdn/index.js CHANGED
@@ -1,5 +1,22 @@
1
- import Pawa from '../index.js'
1
+ import { $state, html, useInsert, RegisterComponent, pawaStartApp } from "../index.js"
2
2
 
3
- // this is for cdn file
4
-
5
- window.$pawa=Pawa
3
+ export const Counter=()=>{
4
+ const count=$state(0)
5
+ useInsert({count})
6
+ return html`
7
+ <div>
8
+ <h1>Counter APPs</h1>
9
+ <h2>@{count.value}</h2>
10
+ <span if="count.value > 0">positive</span>
11
+ <span else-if="count.value < 0">negative</span>
12
+ <span else>It zero</span>
13
+ <button on-click=count.value++>Increment</button>
14
+ <button on-click=count.value-->Decrement</button>
15
+ </div>
16
+ `
17
+ }
18
+ __pawaDev.tool=true
19
+ RegisterComponent(Counter)
20
+ const app=document.getElementById('app')
21
+ pawaStartApp(app)
22
+ window.hmr=true
package/index.js CHANGED
@@ -890,7 +890,7 @@ export const restoreContext = (state_context) => {
890
890
  }
891
891
  export const HmrComponentMap=new Map()
892
892
  const renderedComponentsRusumed=new Set()
893
- export const globalRerender=(el,formercontext)=>{
893
+ export const globalRerender=(el,formercontext,context={})=>{
894
894
  if(!window?.hmr)return
895
895
  let element
896
896
  if (typeof el === 'string') {
@@ -899,7 +899,7 @@ export const globalRerender=(el,formercontext)=>{
899
899
  element=dom.firstElementChild
900
900
  }else element=el
901
901
  formerStateContext=formercontext
902
- normal_component(element,formercontext,setStateContext,mapsPlugins,formercontext,pawaContext,stateWatch)
902
+ normal_component(element,formercontext,setStateContext,mapsPlugins,formercontext,pawaContext,stateWatch,context)
903
903
  }
904
904
  /**
905
905
  *
@@ -2,11 +2,36 @@ import {propsValidator, setPawaDevError, pawaWayRemover, checkKeywordsExistence,
2
2
  import {PawaElement,PawaComment} from '../pawaElement.js';
3
3
  import {keepContext,render, HmrComponentMap } from '../index.js'
4
4
  import {createEffect} from '../reactive.js'
5
- export const normal_component=(el,stateContext,setStateContext,mapsPlugin,formerStateContext,pawaContext,stateWatch)=>{
5
+ function isPawaState(obj) {
6
+ return (
7
+ obj !== null &&
8
+ typeof obj === 'object' &&
9
+ Object.prototype.hasOwnProperty.call(obj, 'value') &&
10
+ typeof obj.id === 'string'
11
+ )
12
+ }
13
+ function restorePawaStateFromContext(oldCtx, newCtx) {
14
+ if (!oldCtx || !newCtx) return
15
+
16
+ for (const key of Object.keys(oldCtx)) {
17
+ const oldVal = oldCtx[key]
18
+ const newVal = newCtx[key]
19
+ if (isPawaState(oldVal) && isPawaState(newVal)) {
20
+ const newOne=newVal.value
21
+ const oldOne=oldVal.value
22
+ if (typeof newOne === typeof oldOne) {
23
+ newVal.value = oldVal.value
24
+ }else if (newVal === null) {
25
+ newVal.value = oldVal.value
26
+ }
27
+ }
28
+ }
29
+ }
30
+ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,formerStateContext,pawaContext,stateWatch,hmrPreserverContext)=>{
6
31
  // Checks if the content is an SVG fragment (graphic elements) without a root <svg> tag.
7
32
  // We exclude 'svg' from the match because a root <svg> tag can be parsed safely inside a <div>.
8
33
  const isSvgFragment = (str) => /^\s*<(path|circle|rect|line|polyline|polygon|ellipse|g|defs|symbol|use|image|text|animate|mask|pattern|clipPath|linearGradient|radialGradient|filter)/i.test(str);
9
-
34
+ const hmr=window?.hmr || false
10
35
  const compoBeforeCall=mapsPlugin.compoBeforeCall
11
36
  const compoAfterCall=mapsPlugin.compoAfterCall
12
37
  const endComment = document.createComment(`end ${el.tagName}`)
@@ -261,6 +286,12 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
261
286
  stateContexts?._error?.forEach((error) => {
262
287
  throw Error(error)
263
288
  })
289
+ if (hmr) {
290
+ if (hmrPreserverContext) {
291
+ restorePawaStateFromContext(context, hmrPreserverContext)
292
+ }
293
+
294
+ }
264
295
  render(child, context)
265
296
  }
266
297
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pawajs",
3
- "version": "2.0.8",
3
+ "version": "2.0.9",
4
4
  "type":"module",
5
5
  "description": "pawajs library (reactive web runtime) for easily building web ui, enhancing html element, micro frontend, spa etc ",
6
6
  "main": "index.js",