pawa-ssr 1.4.0 → 1.4.2
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 +66 -0
- package/index.js +2 -86
- package/package.json +4 -2
- package/pawaElement.js +5 -8
- package/test/App.js +4 -0
- package/test/index.js +22 -7
package/index.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { HTMLElement } from 'linkedom';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Core rendering function that processes PawaElements/HTMLElements and writes to a stream.
|
|
5
|
+
*/
|
|
6
|
+
export function render(el: any, contexts?: object, stream?: (s: string) => void): Promise<void>;
|
|
7
|
+
|
|
8
|
+
export interface StartAppResult {
|
|
9
|
+
element: any;
|
|
10
|
+
toString: () => Promise<string>;
|
|
11
|
+
head: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Initializes and renders the application for standard SSR.
|
|
16
|
+
*/
|
|
17
|
+
export function startApp(
|
|
18
|
+
html: string,
|
|
19
|
+
context?: object,
|
|
20
|
+
development?: boolean
|
|
21
|
+
): Promise<StartAppResult>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Initializes and renders the application using Node.js streams for performance and Suspense support.
|
|
25
|
+
*/
|
|
26
|
+
export function startStreamApp(
|
|
27
|
+
html: string,
|
|
28
|
+
context: object,
|
|
29
|
+
stream: (s: string) => void,
|
|
30
|
+
options: { templateStart: string; templateEnd: string }
|
|
31
|
+
): Promise<void>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Adds custom directives that should be treated as part of the PawaJS directive set.
|
|
35
|
+
*/
|
|
36
|
+
export function addToPartlyDirective(...partly: string[]): void;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Returns an array of all reserved server attributes.
|
|
40
|
+
*/
|
|
41
|
+
export function getAllServerAttrArray(): string[];
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Returns the set of registered Pawa attributes.
|
|
45
|
+
*/
|
|
46
|
+
export function getPawaAttributes(): Set<string>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Checks if the application is running in development mode.
|
|
50
|
+
*/
|
|
51
|
+
export function getDevelopment(): boolean | undefined;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Configures the server-side hooks for PawaJS.
|
|
55
|
+
*/
|
|
56
|
+
export const pawaForServer: (config: {
|
|
57
|
+
useContext: (context: { id: string }) => any;
|
|
58
|
+
useInnerContext: () => any;
|
|
59
|
+
useInsert: (obj?: object) => void;
|
|
60
|
+
setContext: () => { id: string; setValue: (context: object) => void };
|
|
61
|
+
$state: <T>(initialValue: T | (() => T)) => T;
|
|
62
|
+
accessChild: () => void;
|
|
63
|
+
useServer: () => { setServerData: (data: object) => void, getServerData: () => object } | undefined;
|
|
64
|
+
useAsync: () => { $async: <R>(callback: () => R) => R, onSuspense: (html: string) => void } | undefined;
|
|
65
|
+
forwardProps: (props?: object) => void;
|
|
66
|
+
}) => void;
|
package/index.js
CHANGED
|
@@ -243,92 +243,6 @@ const setPawaAttribute=(...attr)=>{
|
|
|
243
243
|
}
|
|
244
244
|
setPawaAttribute('if','else','else-if','for-each','case','switch','s-default','for-key','key')
|
|
245
245
|
export const getPawaAttributes=()=>pawaAttributes
|
|
246
|
-
/**
|
|
247
|
-
* @typedef {{startsWith:string,fullName:string,plugin:(el:HTMLElement | PawaElement,attr:object)=>void}} AttriPlugin
|
|
248
|
-
*/
|
|
249
|
-
/**
|
|
250
|
-
* @typedef {{
|
|
251
|
-
* attribute?:{register:Array<AttriPlugin>},
|
|
252
|
-
* component?:{
|
|
253
|
-
* beforeCall?:(stateContext:PawaComponent,app:object)=>void,
|
|
254
|
-
* afterCall?:(stateContext:PawaComponent,el:HTMLElement)=>void
|
|
255
|
-
* },
|
|
256
|
-
* renderSystem?:{
|
|
257
|
-
* beforePawa?:(el:HTMLElement,context:object)=>void,
|
|
258
|
-
* afterPawa?:(el:PawaElement)=>void,
|
|
259
|
-
* beforeChildRender?:(el:PawaElement)=>void
|
|
260
|
-
* }
|
|
261
|
-
* }} PluginObject
|
|
262
|
-
*/
|
|
263
|
-
/**
|
|
264
|
-
* @param {Array<()=>PluginObject>} func
|
|
265
|
-
*/
|
|
266
|
-
export const PluginSystem=(...func)=>{
|
|
267
|
-
func.forEach(fn=>{
|
|
268
|
-
/**
|
|
269
|
-
* @type {PluginObject}
|
|
270
|
-
*/
|
|
271
|
-
if (typeof fn !== 'function') {
|
|
272
|
-
console.warn('plugin must be a function that returns the plugin objects')
|
|
273
|
-
return
|
|
274
|
-
}
|
|
275
|
-
const getPlugin=fn()
|
|
276
|
-
// attributes plugin or extension
|
|
277
|
-
|
|
278
|
-
if (getPlugin?.attribute) {
|
|
279
|
-
getPlugin.attribute.register.forEach(attrPlugins =>{
|
|
280
|
-
if (attrPlugins.fullName && attrPlugins.startsWith) {
|
|
281
|
-
console.warn('Either Plugins FullName or startsWith. you are not required to use to of does plugin registers at this same entry.')
|
|
282
|
-
return
|
|
283
|
-
}
|
|
284
|
-
if (attrPlugins?.fullName) {
|
|
285
|
-
if (pawaAttributes.has(attrPlugins.fullName) ) {
|
|
286
|
-
console.warn(`attribute plugin already exist ${attrPlugins.fullName}`)
|
|
287
|
-
return
|
|
288
|
-
}
|
|
289
|
-
pawaAttributes.add(attrPlugins.fullName)
|
|
290
|
-
fullNamePlugin.add(attrPlugins.fullName)
|
|
291
|
-
externalPlugin[attrPlugins.fullName]=attrPlugins?.plugin
|
|
292
|
-
}else if (attrPlugins?.startsWith) {
|
|
293
|
-
if (pawaAttributes.has(attrPlugins.startsWith) ) {
|
|
294
|
-
console.warn(`attribute plugin already exist ${attrPlugins.startsWith}`)
|
|
295
|
-
return
|
|
296
|
-
}
|
|
297
|
-
pawaAttributes.add(attrPlugins.startsWith)
|
|
298
|
-
startsWithSet.add(attrPlugins.startsWith)
|
|
299
|
-
externalPlugin[attrPlugins.startsWith]=attrPlugins?.plugin
|
|
300
|
-
}
|
|
301
|
-
})
|
|
302
|
-
}
|
|
303
|
-
if (getPlugin?.component) {
|
|
304
|
-
if (getPlugin.component?.beforeCall && typeof getPlugin.component?.beforeCall === 'function') {
|
|
305
|
-
compoBeforeCall.add(getPlugin.component.beforeCall)
|
|
306
|
-
}
|
|
307
|
-
if (getPlugin.component?.afterCall && typeof getPlugin.component?.afterCall === 'function') {
|
|
308
|
-
compoAfterCall.add(getPlugin.component.afterCall)
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
if (getPlugin?.renderSystem) {
|
|
312
|
-
if (getPlugin.renderSystem?.beforePawa && typeof getPlugin.renderSystem?.beforePawa === 'function') {
|
|
313
|
-
renderBeforePawa.add(getPlugin.renderSystem?.beforePawa)
|
|
314
|
-
}
|
|
315
|
-
if (getPlugin.renderSystem?.afterPawa && typeof getPlugin.renderSystem?.afterPawa === 'function') {
|
|
316
|
-
renderAfterPawa.add(getPlugin.renderSystem?.afterPawa)
|
|
317
|
-
}
|
|
318
|
-
if (getPlugin.renderSystem?.beforeChildRender && typeof getPlugin.renderSystem?.beforeChildRender === 'function') {
|
|
319
|
-
renderBeforeChild.add(getPlugin.renderSystem?.beforeChildRender)
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
})
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
export const useValidateComponent=(component,object)=>{
|
|
326
|
-
if (typeof component === 'function' ) {
|
|
327
|
-
if(component.name){
|
|
328
|
-
component.validateProps=object
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
246
|
|
|
333
247
|
/**
|
|
334
248
|
* @typedef {{
|
|
@@ -724,10 +638,12 @@ appContext.component._prop={children,...el._props,...slots}
|
|
|
724
638
|
if (getChildren.hasAttribute(attr.name)) {
|
|
725
639
|
let attrName=getChildren.getAttribute(attr.name)
|
|
726
640
|
attrName=attr.value +' '+attrName
|
|
641
|
+
|
|
727
642
|
getChildren.setAttribute(attr.name, attrName)
|
|
728
643
|
}else{
|
|
729
644
|
getChildren.setAttribute(attr.name, attr.value)
|
|
730
645
|
}
|
|
646
|
+
// console.log(attr.name,attr.value);
|
|
731
647
|
})
|
|
732
648
|
}
|
|
733
649
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pawa-ssr",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "pawajs ssr libary",
|
|
6
6
|
"main": "index.js",
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
},
|
|
25
25
|
"homepage": "https://github.com/Allisboy/pawajs-ssr#readme",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"linkedom": "^0.18.11"
|
|
27
|
+
"linkedom": "^0.18.11"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
28
30
|
"pawajs": "^2.0.0"
|
|
29
31
|
}
|
|
30
32
|
}
|
package/pawaElement.js
CHANGED
|
@@ -220,13 +220,15 @@ class PawaElement {
|
|
|
220
220
|
hydatename=':'+name
|
|
221
221
|
}
|
|
222
222
|
this._hydrateProps[hydatename]=attr.value
|
|
223
|
+
let value=attr.value
|
|
224
|
+
let context=this._context
|
|
225
|
+
const main={...context}
|
|
223
226
|
const setProps=()=>{
|
|
224
|
-
let value=attr.value
|
|
225
227
|
if (value.includes('@{')) {
|
|
226
228
|
const regex = /@{([^}]*)}/g;
|
|
227
229
|
value = value.replace(regex, (match, expression) => {
|
|
228
230
|
|
|
229
|
-
const res = this.evaluateExpr(expression,
|
|
231
|
+
const res = this.evaluateExpr(expression,{...main},`evaluating props with template operators at ${attr.name} - ${attr.value} : ${this._template}`)
|
|
230
232
|
return res
|
|
231
233
|
|
|
232
234
|
});
|
|
@@ -284,16 +286,11 @@ class PawaElement {
|
|
|
284
286
|
evaluateExpr(expr, context = {},error){
|
|
285
287
|
try {
|
|
286
288
|
const keys = Object.keys(context);
|
|
287
|
-
|
|
288
|
-
// We sort keys to ensure consistent cache hits regardless of key order
|
|
289
|
-
const cacheKey = expr + '|||' + keys.sort().join(',');
|
|
290
|
-
|
|
291
|
-
let func = expressionCache.get(cacheKey);
|
|
289
|
+
let func
|
|
292
290
|
if (!func) {
|
|
293
291
|
func = new Function(...keys, `
|
|
294
292
|
const require=null
|
|
295
293
|
return ${expr}`);
|
|
296
|
-
expressionCache.set(cacheKey, func);
|
|
297
294
|
}
|
|
298
295
|
|
|
299
296
|
const values = keys.map((key) => context[key]);
|
package/test/App.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
import { useInnerContext } from "pawajs"
|
|
2
|
+
|
|
1
3
|
export const App=({children})=>{
|
|
4
|
+
const context=useInnerContext()
|
|
5
|
+
console.log(context)
|
|
2
6
|
return `<div class="p-4">
|
|
3
7
|
<h1 class="text-2xl font-bold mb-4">Hello, World!</h1>
|
|
4
8
|
<p class="text-gray-700">This is a test component for PawaJS.</p>
|
package/test/index.js
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import {useValidateComponent, RegisterComponent,useContext,useInsert,setContext,forwardProps} from 'pawajs'
|
|
2
|
-
import {startApp} from '../index.js'
|
|
2
|
+
import {startApp,startStreamApp} from '../index.js'
|
|
3
3
|
RegisterComponent.lazy(
|
|
4
4
|
'App',()=>import('./App.js'),
|
|
5
5
|
'Check',()=>import('./check.js'),
|
|
6
6
|
'Check2',()=>import('./check.js'),
|
|
7
7
|
)
|
|
8
|
+
const Dtext=({})=>{
|
|
9
|
+
const classActive='class y-p'
|
|
10
|
+
useInsert({classActive})
|
|
11
|
+
return`
|
|
12
|
+
<div class="@{classActive}"></div>
|
|
13
|
+
`
|
|
14
|
+
}
|
|
15
|
+
__pawaDev.tool=true
|
|
8
16
|
const Dinput=({className,...props})=>{
|
|
9
17
|
forwardProps(props)
|
|
10
18
|
const classActive=()=>[className?.() || '','py-2 text-blue'].join(' ')
|
|
@@ -13,12 +21,13 @@ const Dinput=({className,...props})=>{
|
|
|
13
21
|
<input class="@{classActive()}" -- />
|
|
14
22
|
`
|
|
15
23
|
}
|
|
16
|
-
RegisterComponent(Dinput)
|
|
24
|
+
RegisterComponent(Dtext,Dinput)
|
|
17
25
|
const app=`
|
|
18
26
|
<div>
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
|
|
28
|
+
<d-text aschild>
|
|
29
|
+
<dinput type="file" ></dinput>
|
|
30
|
+
</d-text>
|
|
22
31
|
<app>
|
|
23
32
|
<check></check>
|
|
24
33
|
<check-2></check-2>
|
|
@@ -28,5 +37,11 @@ const app=`
|
|
|
28
37
|
</div>
|
|
29
38
|
</div>
|
|
30
39
|
`
|
|
31
|
-
const {toString}=await startApp(app)
|
|
32
|
-
console.log(await toString());
|
|
40
|
+
// const {toString}=await startApp(app)
|
|
41
|
+
// console.log(await toString());
|
|
42
|
+
let strings=''
|
|
43
|
+
const stream=(string)=>strings+=string
|
|
44
|
+
|
|
45
|
+
await startStreamApp(app,{url:'/'},stream,{templateEnd:'</body>',templateStart:'<body>'})
|
|
46
|
+
console.log(strings);
|
|
47
|
+
|