pawa-ssr 1.3.1 → 1.3.3
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/CHANGELOG.md +1 -0
- package/index.js +26 -25
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/index.js
CHANGED
|
@@ -5,6 +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
9
|
|
|
9
10
|
const PAWA_STORE_SYMBOL = Symbol.for('pawa.ssr.store');
|
|
10
11
|
|
|
@@ -134,7 +135,9 @@ const useInnerContext=()=>{
|
|
|
134
135
|
|
|
135
136
|
|
|
136
137
|
const $state = (initialValue) => {
|
|
137
|
-
const
|
|
138
|
+
const id=crypto.randomUUID()
|
|
139
|
+
const state = { value: null ,id};
|
|
140
|
+
|
|
138
141
|
if (typeof initialValue === 'function') {
|
|
139
142
|
const res = initialValue();
|
|
140
143
|
if (res instanceof Promise) {
|
|
@@ -150,18 +153,18 @@ const $state = (initialValue) => {
|
|
|
150
153
|
|
|
151
154
|
const initLocalState = (target, ctx) => {
|
|
152
155
|
const newState = { ...target };
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
} else if (initialValue && typeof initialValue === 'object') {
|
|
156
|
+
const currentValue = target.value;
|
|
157
|
+
|
|
158
|
+
if (currentValue && typeof currentValue === 'object') {
|
|
157
159
|
try {
|
|
158
|
-
newState.value =
|
|
160
|
+
newState.value = structuredClone(currentValue);
|
|
159
161
|
} catch (e) {
|
|
160
|
-
newState.value = Array.isArray(
|
|
162
|
+
newState.value = Array.isArray(currentValue) ? [...currentValue] : { ...currentValue };
|
|
161
163
|
}
|
|
162
164
|
} else {
|
|
163
|
-
newState.value =
|
|
165
|
+
newState.value = currentValue;
|
|
164
166
|
}
|
|
167
|
+
|
|
165
168
|
ctx.states.set(target, newState);
|
|
166
169
|
};
|
|
167
170
|
|
|
@@ -171,7 +174,7 @@ const $state = (initialValue) => {
|
|
|
171
174
|
if (ctx) {
|
|
172
175
|
if (!ctx.states) ctx.states = new Map();
|
|
173
176
|
if (!ctx.states.has(target)) initLocalState(target, ctx);
|
|
174
|
-
return
|
|
177
|
+
return ctx.states.get(target)[prop];
|
|
175
178
|
}
|
|
176
179
|
return Reflect.get(target, prop, receiver);
|
|
177
180
|
},
|
|
@@ -180,12 +183,15 @@ const $state = (initialValue) => {
|
|
|
180
183
|
if (ctx) {
|
|
181
184
|
if (!ctx.states) ctx.states = new Map();
|
|
182
185
|
if (!ctx.states.has(target)) initLocalState(target, ctx);
|
|
183
|
-
|
|
186
|
+
// Directly set the property on the request-local state object.
|
|
187
|
+
ctx.states.get(target)[prop] = value;
|
|
188
|
+
return true; // The set trap must return a boolean.
|
|
184
189
|
}
|
|
185
190
|
return Reflect.set(target, prop, value, receiver);
|
|
186
191
|
}
|
|
187
192
|
});
|
|
188
193
|
};
|
|
194
|
+
|
|
189
195
|
setServer({
|
|
190
196
|
useContext,
|
|
191
197
|
useInnerContext,
|
|
@@ -216,15 +222,10 @@ export const getAllServerAttrArray=()=>{
|
|
|
216
222
|
return allServerAttr;
|
|
217
223
|
}
|
|
218
224
|
|
|
219
|
-
const compoBeforeCall
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const renderBeforeChild=new Set()
|
|
224
|
-
const startsWithSet=new Set()
|
|
225
|
-
const fullNamePlugin=new Set()
|
|
226
|
-
const externalPlugin={}
|
|
227
|
-
const pawaAttributes=new Set()
|
|
225
|
+
const {compoAfterCall,compoBeforeCall,externalPlugin,
|
|
226
|
+
fullNamePlugin,renderAfterPawa,renderBeforeChild,
|
|
227
|
+
renderBeforePawa,startsWithSet
|
|
228
|
+
}=pluginsMap()
|
|
228
229
|
const setPawaAttribute=(...attr)=>{
|
|
229
230
|
attr.forEach(att=>{
|
|
230
231
|
pawaAttributes.add(att)
|
|
@@ -903,9 +904,9 @@ const attributeHandler =async (el, attr) => {
|
|
|
903
904
|
*/
|
|
904
905
|
export const render =async (el, contexts = {},stream) => {
|
|
905
906
|
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
907
|
+
if (checkIfRemove(el) && !el.hasAttribute('switch')) {
|
|
908
|
+
return
|
|
909
|
+
}
|
|
909
910
|
const isStream=store.getStore().stream
|
|
910
911
|
if(el.hasAttribute('only-client')){
|
|
911
912
|
el.removeAttribute('only-client')
|
|
@@ -937,7 +938,7 @@ export const render =async (el, contexts = {},stream) => {
|
|
|
937
938
|
console.error(error.message,error.stack)
|
|
938
939
|
}
|
|
939
940
|
}
|
|
940
|
-
|
|
941
|
+
const stateContext=store.getStore().stateContext
|
|
941
942
|
PawaElement.Element(el,context)
|
|
942
943
|
if(el.childNodes.some(node=>node.nodeType === 3 && node.nodeValue.includes('@{')) && !el._avoidPawaRender){
|
|
943
944
|
await textContentHandler(el)
|
|
@@ -982,7 +983,7 @@ export const render =async (el, contexts = {},stream) => {
|
|
|
982
983
|
console.warn(`${attr.name} plugin must be a function`)
|
|
983
984
|
return
|
|
984
985
|
}
|
|
985
|
-
await plugin(el,attr)
|
|
986
|
+
await plugin(el,attr,stateContext,stream)// on client no stream but an object called notRender
|
|
986
987
|
}catch(error){
|
|
987
988
|
console.warn(error.message,error.stack)
|
|
988
989
|
}
|
|
@@ -996,7 +997,7 @@ export const render =async (el, contexts = {},stream) => {
|
|
|
996
997
|
console.warn(`${name} plugin must be a function`)
|
|
997
998
|
return
|
|
998
999
|
}
|
|
999
|
-
await plugin(el,attr)
|
|
1000
|
+
await plugin(el,attr,stateContext,stream)
|
|
1000
1001
|
}catch(error){
|
|
1001
1002
|
console.warn(error.message,error.stack)
|
|
1002
1003
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pawa-ssr",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.3",
|
|
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.11"
|
|
29
29
|
}
|
|
30
30
|
}
|