pawa-ssr 1.4.0 → 1.4.1

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 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 {{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pawa-ssr",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
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
@@ -284,16 +284,11 @@ class PawaElement {
284
284
  evaluateExpr(expr, context = {},error){
285
285
  try {
286
286
  const keys = Object.keys(context);
287
- // Create a cache key based on the expression and the available context keys
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);
287
+ let func
292
288
  if (!func) {
293
289
  func = new Function(...keys, `
294
290
  const require=null
295
291
  return ${expr}`);
296
- expressionCache.set(cacheKey, func);
297
292
  }
298
293
 
299
294
  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,5 +1,5 @@
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'),
@@ -17,7 +17,7 @@ RegisterComponent(Dinput)
17
17
  const app=`
18
18
  <div>
19
19
  <dinput type="file" aschild>
20
- <div>input</div>
20
+ <div>aschild</div>
21
21
  </dinput>
22
22
  <app>
23
23
  <check></check>
@@ -28,5 +28,11 @@ const app=`
28
28
  </div>
29
29
  </div>
30
30
  `
31
- const {toString}=await startApp(app)
32
- console.log(await toString());
31
+ // const {toString}=await startApp(app)
32
+ // console.log(await toString());
33
+ let strings=''
34
+ const stream=(string)=>strings+=string
35
+
36
+ await startStreamApp(app,{url:'/'},stream,{templateEnd:'</body>',templateStart:'<body>'})
37
+ console.log(strings);
38
+