pawajs 2.0.8 → 2.0.10
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 +25 -0
- package/cdn/index.js +21 -4
- package/index.d.ts +1 -1
- package/index.js +2 -2
- package/normal/component.js +38 -2
- package/package.json +1 -1
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
|
|
1
|
+
import { $state, html, useInsert, RegisterComponent, pawaStartApp } from "../index.js"
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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.d.ts
CHANGED
|
@@ -384,7 +384,7 @@ export function forwardProps(props?: Record<string, any>): void;
|
|
|
384
384
|
export function useInsert(obj?: Record<string, any>): void;
|
|
385
385
|
|
|
386
386
|
export function setStateContext(context: any): any;
|
|
387
|
-
export function globalRerender(el:HTMLElement | string,formercontext)
|
|
387
|
+
export function globalRerender(el:HTMLElement | string,formercontext:StateContextType,context:any)
|
|
388
388
|
/**
|
|
389
389
|
* Creates a reactive state.
|
|
390
390
|
* @template T
|
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
|
*
|
package/normal/component.js
CHANGED
|
@@ -2,11 +2,42 @@ 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
|
-
|
|
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
|
+
|
|
15
|
+
if (!oldCtx || !newCtx) return
|
|
16
|
+
|
|
17
|
+
for (const key of Object.keys(newCtx)) {
|
|
18
|
+
console.log(key,'inside preserverState');
|
|
19
|
+
|
|
20
|
+
const oldVal = oldCtx[key]
|
|
21
|
+
const newVal = newCtx[key]
|
|
22
|
+
if (isPawaState(oldVal) && isPawaState(newVal)) {
|
|
23
|
+
|
|
24
|
+
const newOne=newVal.value
|
|
25
|
+
const oldOne=oldVal.value
|
|
26
|
+
if (typeof newOne === typeof oldOne) {
|
|
27
|
+
newVal.value = oldVal.value
|
|
28
|
+
}else if (newVal === null) {
|
|
29
|
+
newVal.value = oldVal.value
|
|
30
|
+
}
|
|
31
|
+
console.log('is updating',key, newVal,'from',oldVal);
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export const normal_component=(el,stateContext,setStateContext,mapsPlugin,formerStateContext,pawaContext,stateWatch,hmrPreserverContext)=>{
|
|
6
37
|
// Checks if the content is an SVG fragment (graphic elements) without a root <svg> tag.
|
|
7
38
|
// We exclude 'svg' from the match because a root <svg> tag can be parsed safely inside a <div>.
|
|
8
39
|
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
|
-
|
|
40
|
+
const hmr=window?.hmr || false
|
|
10
41
|
const compoBeforeCall=mapsPlugin.compoBeforeCall
|
|
11
42
|
const compoAfterCall=mapsPlugin.compoAfterCall
|
|
12
43
|
const endComment = document.createComment(`end ${el.tagName}`)
|
|
@@ -164,6 +195,9 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
|
|
|
164
195
|
|
|
165
196
|
div.innerHTML = compo;
|
|
166
197
|
if (component?._insert) {
|
|
198
|
+
if (hmrPreserverContext) {
|
|
199
|
+
restorePawaStateFromContext(hmrPreserverContext,component._insert)
|
|
200
|
+
}
|
|
167
201
|
Object.assign(el._context,component._insert)
|
|
168
202
|
}
|
|
169
203
|
const restProps={}
|
|
@@ -261,6 +295,8 @@ export const normal_component=(el,stateContext,setStateContext,mapsPlugin,former
|
|
|
261
295
|
stateContexts?._error?.forEach((error) => {
|
|
262
296
|
throw Error(error)
|
|
263
297
|
})
|
|
298
|
+
|
|
299
|
+
|
|
264
300
|
render(child, context)
|
|
265
301
|
}
|
|
266
302
|
}
|
package/package.json
CHANGED