pawa-ssr 1.3.9 → 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 +32 -30
- package/package.json +2 -2
- package/pawaElement.js +10 -3
- package/power.js +2 -1
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
|
|
|
@@ -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
|
@@ -255,7 +255,7 @@ export const For=async(el,attr,stream)=>{
|
|
|
255
255
|
if (at.name.startsWith('c-')) {
|
|
256
256
|
store.push(at)
|
|
257
257
|
copyElement.removeAttribute(at.name)
|
|
258
|
-
}
|
|
258
|
+
}
|
|
259
259
|
})
|
|
260
260
|
|
|
261
261
|
const template=document.createElement('template')
|
|
@@ -334,6 +334,7 @@ export const For=async(el,attr,stream)=>{
|
|
|
334
334
|
}
|
|
335
335
|
}
|
|
336
336
|
|
|
337
|
+
|
|
337
338
|
export const State=async(el,attr)=>{
|
|
338
339
|
if (el._running) {
|
|
339
340
|
return
|