pawa-ssr 1.3.8 → 1.3.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/index.js +33 -31
- package/package.json +2 -2
- package/pawaElement.js +10 -3
- package/power.js +72 -90
package/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { propsValidator, evaluateExpr,extractAtExpressions, reArrangeAttri,resum
|
|
|
5
5
|
import {AsyncLocalStorage} from'node:async_hooks'
|
|
6
6
|
import { If,For,State,Switch, Key } from'./power.js';
|
|
7
7
|
import PawaElement from'./pawaElement.js'
|
|
8
|
-
import { pluginsMap } from "pawajs";
|
|
8
|
+
import { pluginsMap, lazyComponents } from "pawajs";
|
|
9
9
|
|
|
10
10
|
const PAWA_STORE_SYMBOL = Symbol.for('pawa.ssr.store');
|
|
11
11
|
|
|
@@ -889,7 +889,7 @@ const attributeHandler =async (el, attr) => {
|
|
|
889
889
|
partlyPawajsDirective.add(v)
|
|
890
890
|
})
|
|
891
891
|
}
|
|
892
|
-
addToPartlyDirective('else','else-if','case')
|
|
892
|
+
addToPartlyDirective('else','else-if','case','default')
|
|
893
893
|
const checkIfRemove=(el)=>{
|
|
894
894
|
for (const v of partlyPawajsDirective) {
|
|
895
895
|
if(el.hasAttribute(v)) return true
|
|
@@ -1016,6 +1016,13 @@ export const render =async (el, contexts = {},stream) => {
|
|
|
1016
1016
|
return
|
|
1017
1017
|
}
|
|
1018
1018
|
if (el._componentName) {
|
|
1019
|
+
if(el._lazy && lazyComponents.has(el.tagName)){
|
|
1020
|
+
const lazyComponent=lazyComponents.has(el.tagName)
|
|
1021
|
+
const {name,component} =lazyComponent()
|
|
1022
|
+
components.set(name,component)
|
|
1023
|
+
el._component.component=component
|
|
1024
|
+
lazyComponents.delete(el.tagName)
|
|
1025
|
+
}
|
|
1019
1026
|
if(isStream){
|
|
1020
1027
|
await streamingComponent(el,stream)
|
|
1021
1028
|
return
|
|
@@ -1206,7 +1213,7 @@ const resolvesAsync=async({component,
|
|
|
1206
1213
|
const bufferStream=(string)=>{
|
|
1207
1214
|
chunk+=string
|
|
1208
1215
|
}
|
|
1209
|
-
bufferStream(`<div id="
|
|
1216
|
+
bufferStream(`<div id="res-${id}" hidden>`)
|
|
1210
1217
|
store.getStore().stateContext=appContext
|
|
1211
1218
|
const compo=await component.then((res)=>res)
|
|
1212
1219
|
const div=root.createElement('div')
|
|
@@ -1245,36 +1252,31 @@ const resolvesAsync=async({component,
|
|
|
1245
1252
|
bufferStream(`
|
|
1246
1253
|
<script class="p${id}">
|
|
1247
1254
|
const s${id}=()=>{
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
}
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
if(a.name === 'p-async') return
|
|
1263
|
-
if (a.name === 'p:c') {
|
|
1264
|
-
let o=a.value + (fc.getAttribute('p:c') || '')
|
|
1265
|
-
fc.setAttribute('p:c',o)
|
|
1266
|
-
}else{
|
|
1267
|
-
fc.setAttribute(a.name,a.value)
|
|
1255
|
+
const placeholder = document.getElementById("p${id}");
|
|
1256
|
+
const resolved = document.getElementById("res-${id}");
|
|
1257
|
+
if(!placeholder || !resolved) return;
|
|
1258
|
+
|
|
1259
|
+
const comment = placeholder.previousSibling;
|
|
1260
|
+
if(comment && comment.nodeType === 8) comment.data = '${commentData}';
|
|
1261
|
+
|
|
1262
|
+
const firstChild = resolved.firstElementChild;
|
|
1263
|
+
Array.from(placeholder.attributes).forEach(a => {
|
|
1264
|
+
if(a.name === 'p-async') return;
|
|
1265
|
+
if (a.name === 'p:c') {
|
|
1266
|
+
firstChild.setAttribute('p:c', a.value + (firstChild.getAttribute('p:c') || ''));
|
|
1267
|
+
} else {
|
|
1268
|
+
firstChild.setAttribute(a.name, a.value);
|
|
1268
1269
|
}
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1270
|
+
});
|
|
1271
|
+
|
|
1272
|
+
while(resolved.firstChild) placeholder.parentNode.insertBefore(resolved.firstChild, placeholder);
|
|
1273
|
+
placeholder.remove();
|
|
1274
|
+
resolved.remove();
|
|
1275
|
+
|
|
1276
|
+
if (window?.__pawaDev) {
|
|
1277
|
+
window.__pawaStream(firstChild, {}, {});
|
|
1277
1278
|
}
|
|
1279
|
+
}
|
|
1278
1280
|
s${id}()
|
|
1279
1281
|
document.querySelector('.p${id}').remove()
|
|
1280
1282
|
</script>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pawa-ssr",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.10",
|
|
4
4
|
"type":"module",
|
|
5
5
|
"description": "pawajs ssr libary",
|
|
6
6
|
"main": "index.js",
|
|
@@ -25,6 +25,6 @@
|
|
|
25
25
|
"homepage": "https://github.com/Allisboy/pawajs-ssr#readme",
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"linkedom": "^0.18.11",
|
|
28
|
-
"pawajs": "^1.4.
|
|
28
|
+
"pawajs": "^1.4.35"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/pawaElement.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HTMLElement, parseHTML } from "linkedom"
|
|
2
2
|
import {getPawaAttributes, getDevelopment } from "./index.js"
|
|
3
|
-
import {components} from 'pawajs'
|
|
3
|
+
import {components,lazyComponents} from 'pawajs'
|
|
4
4
|
import PawaComponent from "./pawaComponent.js"
|
|
5
5
|
import { evaluateExpr, splitAndAdd,replaceTemplateOperators } from "./utils.js"
|
|
6
6
|
|
|
@@ -32,6 +32,7 @@ class PawaElement {
|
|
|
32
32
|
this._pawaAlready=element.hasAttribute('p:c')
|
|
33
33
|
/**@type {Array<{message:string,stack:string}>} */
|
|
34
34
|
this._error=[]
|
|
35
|
+
this._lazy=false
|
|
35
36
|
this._running=false
|
|
36
37
|
this._hasForOrIf=this.hasForOrIf
|
|
37
38
|
this._createError=this.createError
|
|
@@ -77,6 +78,11 @@ class PawaElement {
|
|
|
77
78
|
this._arrangeAttribute[value.name]=value.value
|
|
78
79
|
})
|
|
79
80
|
}
|
|
81
|
+
checkLazy(){
|
|
82
|
+
if (lazyComponents.has(this._el.tagName)) {
|
|
83
|
+
this._lazy=true
|
|
84
|
+
}
|
|
85
|
+
}
|
|
80
86
|
setResumeAttr(name){
|
|
81
87
|
if(name.startsWith(':')) return
|
|
82
88
|
this._resumeAttr+=`${name};`
|
|
@@ -149,9 +155,10 @@ class PawaElement {
|
|
|
149
155
|
}
|
|
150
156
|
|
|
151
157
|
getComponent(){
|
|
152
|
-
if (components.has(splitAndAdd(this._el.tagName.toUpperCase())) && !this._client) {
|
|
158
|
+
if (components.has(splitAndAdd(this._el.tagName.toUpperCase())) && !this._client || this._lazy) {
|
|
153
159
|
this._componentName=splitAndAdd(this._el.tagName.toUpperCase())
|
|
154
|
-
|
|
160
|
+
const fakeCompo=()=>true
|
|
161
|
+
this._component=new PawaComponent(components.get(splitAndAdd(this._el.tagName.toUpperCase())),fakeCompo)
|
|
155
162
|
Array.from(this._el.children).forEach(slot =>{
|
|
156
163
|
|
|
157
164
|
if (slot.tagName === 'TEMPLATE' && slot.getAttribute('prop')) {
|
package/power.js
CHANGED
|
@@ -13,31 +13,28 @@ export const If = async(el, attr,stream) => {
|
|
|
13
13
|
}]
|
|
14
14
|
const chainMap=new Map()
|
|
15
15
|
chainMap.set(el.getAttribute('if'),{condition:'if',element:el})
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
getChained(nextSiblings)
|
|
16
|
+
const getChained = (sibling) => {
|
|
17
|
+
while (sibling) {
|
|
18
|
+
const next = sibling.nextElementSibling;
|
|
19
|
+
const isElseIf = sibling.hasAttribute('else-if');
|
|
20
|
+
const isElse = sibling.hasAttribute('else');
|
|
21
|
+
|
|
22
|
+
if (isElseIf) {
|
|
23
|
+
const exp = sibling.getAttribute('else-if');
|
|
24
|
+
chained.push({ exp, condition: 'else-if', element: sibling });
|
|
25
|
+
chainMap.set(exp, { condition: 'else-if', element: sibling });
|
|
26
|
+
sibling.remove();
|
|
27
|
+
} else if (isElse) {
|
|
28
|
+
chained.push({ exp: 'false', condition: 'else', element: sibling });
|
|
29
|
+
chainMap.set('else', { condition: 'else', element: sibling });
|
|
30
|
+
sibling.remove();
|
|
31
|
+
} else {
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
sibling = next;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
getChained(nextSiblings)
|
|
41
38
|
let func=new Map()
|
|
42
39
|
let current
|
|
43
40
|
let latestChain
|
|
@@ -66,24 +63,17 @@ let latestChain
|
|
|
66
63
|
let stringHtml=''
|
|
67
64
|
const template=document.createElement('template')
|
|
68
65
|
const store=document.createElement('template')
|
|
69
|
-
chained.forEach((item
|
|
70
|
-
const clone=item.element.cloneNode(true)
|
|
71
|
-
clone._avoidPawaRender = true
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
store.appendChild(clone)
|
|
81
|
-
}else{
|
|
82
|
-
store.appendChild(clone)
|
|
83
|
-
}
|
|
84
|
-
template.appendChild(item.element)
|
|
85
|
-
|
|
86
|
-
})
|
|
66
|
+
chained.forEach((item) => {
|
|
67
|
+
const clone = item.element.cloneNode(true);
|
|
68
|
+
clone._avoidPawaRender = true;
|
|
69
|
+
Array.from(clone.attributes).forEach(at => {
|
|
70
|
+
if (at.name.startsWith('c-') || at.name === 'p:c') {
|
|
71
|
+
clone.removeAttribute(at.name);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
store.appendChild(clone);
|
|
75
|
+
template.appendChild(item.element);
|
|
76
|
+
});
|
|
87
77
|
const getRightElement=chainMap.get(latestChain.id)
|
|
88
78
|
if (getRightElement) {
|
|
89
79
|
const copyElement=getRightElement.element.cloneNode(true)
|
|
@@ -133,31 +123,28 @@ export const Switch = async(el, attr,stream) => {
|
|
|
133
123
|
}]
|
|
134
124
|
const chainMap=new Map()
|
|
135
125
|
chainMap.set(el.getAttribute('case'),{condition:'case',element:el})
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
getChained(nextSiblings)
|
|
126
|
+
const getChained = (sibling) => {
|
|
127
|
+
while (sibling) {
|
|
128
|
+
const next = sibling.nextElementSibling;
|
|
129
|
+
const isCase = sibling.hasAttribute('case');
|
|
130
|
+
const isDefault = sibling.hasAttribute('default');
|
|
131
|
+
|
|
132
|
+
if (isCase) {
|
|
133
|
+
const exp = sibling.getAttribute('case');
|
|
134
|
+
chained.push({ exp, condition: 'case', element: sibling });
|
|
135
|
+
chainMap.set(exp, { condition: 'case', element: sibling });
|
|
136
|
+
sibling.remove();
|
|
137
|
+
} else if (isDefault) {
|
|
138
|
+
chained.push({ exp: 'false', condition: 'default', element: sibling });
|
|
139
|
+
chainMap.set('default', { condition: 'default', element: sibling });
|
|
140
|
+
sibling.remove();
|
|
141
|
+
} else {
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
sibling = next;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
getChained(nextSiblings)
|
|
161
148
|
let func=new Map()
|
|
162
149
|
let current
|
|
163
150
|
let latestChain
|
|
@@ -187,24 +174,18 @@ const switchFunc=el._evaluateExpr(attr.value,el._context,`at switch directive ${
|
|
|
187
174
|
let stringHtml=''
|
|
188
175
|
const template=document.createElement('template')
|
|
189
176
|
const store=document.createElement('template')
|
|
190
|
-
let index=0
|
|
191
|
-
chained.forEach(item =>{
|
|
192
|
-
const clone=item.element.cloneNode(true)
|
|
193
|
-
clone._avoidPawaRender = true
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}else{
|
|
203
|
-
store.appendChild(clone)
|
|
204
|
-
}
|
|
205
|
-
index++
|
|
206
|
-
template.appendChild(item.element)
|
|
207
|
-
})
|
|
177
|
+
// let index=0
|
|
178
|
+
chained.forEach((item) => {
|
|
179
|
+
const clone = item.element.cloneNode(true);
|
|
180
|
+
clone._avoidPawaRender = true;
|
|
181
|
+
Array.from(clone.attributes).forEach(at => {
|
|
182
|
+
if (at.name.startsWith('c-') || at.name === 'p:c') {
|
|
183
|
+
clone.removeAttribute(at.name);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
store.appendChild(clone);
|
|
187
|
+
template.appendChild(item.element);
|
|
188
|
+
});
|
|
208
189
|
el.removeAttribute('switch')
|
|
209
190
|
const getRightElement=chainMap.get(latestChain.id)
|
|
210
191
|
if (getRightElement && (current || latestChain.condition === 'default')) {
|
|
@@ -274,7 +255,7 @@ export const For=async(el,attr,stream)=>{
|
|
|
274
255
|
if (at.name.startsWith('c-')) {
|
|
275
256
|
store.push(at)
|
|
276
257
|
copyElement.removeAttribute(at.name)
|
|
277
|
-
}
|
|
258
|
+
}
|
|
278
259
|
})
|
|
279
260
|
|
|
280
261
|
const template=document.createElement('template')
|
|
@@ -353,6 +334,7 @@ export const For=async(el,attr,stream)=>{
|
|
|
353
334
|
}
|
|
354
335
|
}
|
|
355
336
|
|
|
337
|
+
|
|
356
338
|
export const State=async(el,attr)=>{
|
|
357
339
|
if (el._running) {
|
|
358
340
|
return
|
|
@@ -394,9 +376,9 @@ export const Key=async(el,attr,stream)=>{
|
|
|
394
376
|
const template=document.createElement('template')
|
|
395
377
|
template.setAttribute('p:store-key',dirId)
|
|
396
378
|
template.setAttribute('p:store','')
|
|
397
|
-
clone.attributes.forEach(at => {
|
|
398
|
-
if (at.name.startsWith('c-')) {
|
|
399
|
-
clone.removeAttribute(at.name)
|
|
379
|
+
Array.from(clone.attributes).forEach(at => {
|
|
380
|
+
if (at.name.startsWith('c-') || at.name === 'p:c') {
|
|
381
|
+
clone.removeAttribute(at.name);
|
|
400
382
|
}
|
|
401
383
|
});
|
|
402
384
|
template.appendChild(clone)
|