pawajs 2.0.3 → 2.0.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.d.ts +27 -2
- package/index.js +15 -1
- package/package.json +1 -1
- package/pawaElement.js +25 -21
package/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface PawaElement extends HTMLElement {
|
|
|
10
10
|
_terminateEffects: Set<Function>;
|
|
11
11
|
_deleteEffects: () => void;
|
|
12
12
|
_slots: DocumentFragment;
|
|
13
|
-
_stateContext:
|
|
13
|
+
_stateContext: StateContextType;
|
|
14
14
|
_mainAttribute: Record<string, any>;
|
|
15
15
|
_preRenderAvoid: string[];
|
|
16
16
|
_lazy: boolean;
|
|
@@ -118,6 +118,31 @@ export interface PawaDev {
|
|
|
118
118
|
logEffect(e: any, t: any): void;
|
|
119
119
|
logComponent(n: any, t: any): void;
|
|
120
120
|
}
|
|
121
|
+
type StateContextType={
|
|
122
|
+
_name:string,
|
|
123
|
+
_props:object,
|
|
124
|
+
_formerStateContext:stateContextType,
|
|
125
|
+
_elementContext:object,
|
|
126
|
+
_template:string,
|
|
127
|
+
_reactiveProps:object,
|
|
128
|
+
_restProps:object,
|
|
129
|
+
_hasRun:boolean,
|
|
130
|
+
_transportContext:object,
|
|
131
|
+
_static:any[],
|
|
132
|
+
_serializedData:object,
|
|
133
|
+
_formerContext:stateContextType,
|
|
134
|
+
_resume:boolean,
|
|
135
|
+
_suspense:string,
|
|
136
|
+
_hmr:boolean,
|
|
137
|
+
_hook:{
|
|
138
|
+
beforeMount:Function[],
|
|
139
|
+
reactiveEffect:Function[],
|
|
140
|
+
effect:Function[],
|
|
141
|
+
isMount:Function[],
|
|
142
|
+
isUnMount:Function[]
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
export const statecontext:StateContextType
|
|
121
146
|
|
|
122
147
|
declare global {
|
|
123
148
|
var __pawaDev: PawaDev;
|
|
@@ -359,7 +384,7 @@ export function forwardProps(props?: Record<string, any>): void;
|
|
|
359
384
|
export function useInsert(obj?: Record<string, any>): void;
|
|
360
385
|
|
|
361
386
|
export function setStateContext(context: any): any;
|
|
362
|
-
|
|
387
|
+
export function globalRerender(el:HTMLElement | string,formercontext)
|
|
363
388
|
/**
|
|
364
389
|
* Creates a reactive state.
|
|
365
390
|
* @template T
|
package/index.js
CHANGED
|
@@ -890,6 +890,17 @@ 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)=>{
|
|
894
|
+
if(!window?.hmr)return
|
|
895
|
+
let element
|
|
896
|
+
if (typeof el === 'string') {
|
|
897
|
+
const dom =document.createDocumentFragment()
|
|
898
|
+
dom.innerHTML=el
|
|
899
|
+
element=dom.firstElementChild
|
|
900
|
+
}else element=el
|
|
901
|
+
formerStateContext=formercontext
|
|
902
|
+
normal_component(element,formercontext,setStateContext,mapsPlugins,formercontext,pawaContext,stateWatch)
|
|
903
|
+
}
|
|
893
904
|
/**
|
|
894
905
|
*
|
|
895
906
|
* @param {PawaElement|HTMLElement} el
|
|
@@ -1363,7 +1374,10 @@ if (typeof window !== 'undefined') {
|
|
|
1363
1374
|
|
|
1364
1375
|
}
|
|
1365
1376
|
export const pawaStartApp = (app, context = {}) => {
|
|
1366
|
-
|
|
1377
|
+
if (app?.tagName && app.hasAttribute('pawa-app') === false) {
|
|
1378
|
+
app.setAttribute('pawa-app', '')
|
|
1379
|
+
render(app, context)
|
|
1380
|
+
}
|
|
1367
1381
|
}
|
|
1368
1382
|
|
|
1369
1383
|
/**
|
package/package.json
CHANGED
package/pawaElement.js
CHANGED
|
@@ -10,6 +10,7 @@ import { lazyComponentElement } from './index.js';
|
|
|
10
10
|
export class PawaElement {
|
|
11
11
|
|
|
12
12
|
#context
|
|
13
|
+
#el
|
|
13
14
|
/**
|
|
14
15
|
*
|
|
15
16
|
* @param {HTMLElement} element
|
|
@@ -17,10 +18,11 @@ export class PawaElement {
|
|
|
17
18
|
*/
|
|
18
19
|
constructor(element,context) {
|
|
19
20
|
this.#context=context
|
|
21
|
+
this.#el=element
|
|
20
22
|
const div=element.cloneNode(true)
|
|
21
23
|
Object.assign(this, {
|
|
22
24
|
_resetEffects: new Set(), _context: context, _avoidPawaRender: element.hasAttribute('pawa-avoid'),
|
|
23
|
-
|
|
25
|
+
_out: false, _stateContext: null, _terminateEffects: new Set(), _deleteEffects: this.terminateEffects,
|
|
24
26
|
_slots: document.createDocumentFragment(), _mainAttribute: {}, _preRenderAvoid: [], _running: false,
|
|
25
27
|
_hasForOrIf: this.hasForOrIf, _elementContent: element.textContent, _textContent: {}, _attributes: [],
|
|
26
28
|
_template: div.outerHTML, _exitAnimation: null, _component: null, _unMountFunctions: [], _MountFunctions: [],_beforeUnMountFunctions:[],
|
|
@@ -48,13 +50,13 @@ export class PawaElement {
|
|
|
48
50
|
Object.assign(element,pawa)
|
|
49
51
|
}
|
|
50
52
|
getChildrenTree(){
|
|
51
|
-
return Array.from(this.
|
|
53
|
+
return Array.from(this.#el.children)
|
|
52
54
|
}
|
|
53
55
|
checkLazy(){
|
|
54
|
-
if (lazyComponents.has(splitAndAdd(this.
|
|
55
|
-
if(components.has(splitAndAdd(this.
|
|
56
|
+
if (lazyComponents.has(splitAndAdd(this.#el.tagName))) {
|
|
57
|
+
if(components.has(splitAndAdd(this.#el.tagName))) return
|
|
56
58
|
this._lazy=true
|
|
57
|
-
triggerLazyLoad(splitAndAdd(this.
|
|
59
|
+
triggerLazyLoad(splitAndAdd(this.#el.tagName))
|
|
58
60
|
|
|
59
61
|
}
|
|
60
62
|
}
|
|
@@ -93,24 +95,24 @@ export class PawaElement {
|
|
|
93
95
|
})
|
|
94
96
|
}
|
|
95
97
|
setPawaAttr(){
|
|
96
|
-
const isResume=this.
|
|
97
|
-
if (this.
|
|
98
|
+
const isResume=this.#el.hasAttribute('p:c')
|
|
99
|
+
if (this.#el.hasAttribute('p-async')) return
|
|
98
100
|
if(isResume){
|
|
99
|
-
const pawaAttr=this.
|
|
101
|
+
const pawaAttr=this.#el.getAttribute('p:c')
|
|
100
102
|
const array=pawaAttr.split(';')
|
|
101
103
|
array.forEach(value =>{
|
|
102
|
-
if(!this.
|
|
104
|
+
if(!this.#el.hasAttribute(value.toLowerCase())) {
|
|
103
105
|
return
|
|
104
106
|
}
|
|
105
|
-
this._attributes.push({name:value,value:this.
|
|
106
|
-
// console.log(this
|
|
107
|
+
this._attributes.push({name:value,value:this.#el.getAttribute(value.toLowerCase())})
|
|
108
|
+
// console.log(this.#el,this._attributes);
|
|
107
109
|
})
|
|
108
110
|
}else{
|
|
109
|
-
this._attributes=Array.from(this.
|
|
111
|
+
this._attributes=Array.from(this.#el.attributes)
|
|
110
112
|
}
|
|
111
113
|
}
|
|
112
114
|
findPawaAttribute(){
|
|
113
|
-
Array.from(this.
|
|
115
|
+
Array.from(this.#el.attributes).forEach((attr) => {
|
|
114
116
|
const pawaAttribute=getPawaAttributes()
|
|
115
117
|
const dependentAttribute=getDependentAttribute()
|
|
116
118
|
if (pawaAttribute.has(attr.name) && !dependentAttribute.has(attr.name)) {
|
|
@@ -143,7 +145,7 @@ export class PawaElement {
|
|
|
143
145
|
}
|
|
144
146
|
|
|
145
147
|
getNewElementByRemovingAttr(attrName){
|
|
146
|
-
const element=this.
|
|
148
|
+
const element=this.#el.cloneNode(true)
|
|
147
149
|
element.removeAttribute(attrName)
|
|
148
150
|
return element
|
|
149
151
|
}
|
|
@@ -179,8 +181,10 @@ export class PawaElement {
|
|
|
179
181
|
async remove(callback){
|
|
180
182
|
|
|
181
183
|
await this._beforeUnMount()
|
|
184
|
+
if (window?.hmr) {
|
|
185
|
+
this._exitAnimation=null
|
|
186
|
+
}
|
|
182
187
|
if (typeof this._exitAnimation === 'function') {
|
|
183
|
-
|
|
184
188
|
try {
|
|
185
189
|
const animate=this._exitAnimation().then(async () => {
|
|
186
190
|
await this._callUnmount()
|
|
@@ -252,21 +256,21 @@ export class PawaElement {
|
|
|
252
256
|
if (this._avoidPawaRender) {
|
|
253
257
|
return
|
|
254
258
|
}
|
|
255
|
-
const tag = this.
|
|
259
|
+
const tag = this.#el.tagName
|
|
256
260
|
try {
|
|
257
|
-
if (components.has(splitAndAdd(tag)) || this._lazy && !this.
|
|
261
|
+
if (components.has(splitAndAdd(tag)) || this._lazy && !this.#el.hasAttribute('data-prevent:c')) {
|
|
258
262
|
this._elementType='component'
|
|
259
263
|
this._componentOrTemplate=true
|
|
260
264
|
this._deCompositionElement=true
|
|
261
265
|
this._componentName=splitAndAdd(tag)
|
|
262
266
|
const forLazy=()=>true
|
|
263
267
|
this._component=new PawaComponent(components.get(splitAndAdd(tag)) || forLazy)
|
|
264
|
-
Array.from(this.
|
|
268
|
+
Array.from(this.#el.children).forEach(slot =>{
|
|
265
269
|
if (slot.tagName === 'TEMPLATE' && slot.getAttribute('prop') && !slot.hasAttribute('js')) {
|
|
266
270
|
this._slots.appendChild(slot)
|
|
267
271
|
}
|
|
268
272
|
})
|
|
269
|
-
this._componentChildren=this.
|
|
273
|
+
this._componentChildren=this.#el.innerHTML
|
|
270
274
|
|
|
271
275
|
} else if(tag ==='TEMPLATE'){
|
|
272
276
|
this._elementType='template'
|
|
@@ -295,9 +299,9 @@ export class PawaElement {
|
|
|
295
299
|
return
|
|
296
300
|
}
|
|
297
301
|
if (this._componentName) {
|
|
298
|
-
const hasPC=this.
|
|
302
|
+
const hasPC=this.#el.hasAttribute('p:c')
|
|
299
303
|
if (hasPC) {
|
|
300
|
-
Array.from(this.
|
|
304
|
+
Array.from(this.#el.attributes).forEach(attr => {
|
|
301
305
|
if (attr.name.startsWith('c-') || attr.name === 'by') return
|
|
302
306
|
this._attributes.push({name:attr.name,value:attr.value})
|
|
303
307
|
});
|