@coherent.js/nextjs 1.0.0-beta.3 → 1.0.0-beta.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coherent.js/nextjs",
3
- "version": "1.0.0-beta.3",
3
+ "version": "1.0.0-beta.6",
4
4
  "description": "Next.js integration for Coherent.js",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -29,11 +29,12 @@
29
29
  "peerDependencies": {
30
30
  "next": ">=13.0.0 < 16.0.0",
31
31
  "react": ">=18.0.0 < 20.0.0",
32
- "@coherent.js/core": "1.0.0-beta.3"
32
+ "@coherent.js/core": "1.0.0-beta.6"
33
33
  },
34
34
  "publishConfig": {
35
35
  "access": "public"
36
36
  },
37
+ "sideEffects": false,
37
38
  "scripts": {
38
39
  "build": "node build.mjs",
39
40
  "clean": "rm -rf dist/",
package/types/index.d.ts CHANGED
@@ -5,8 +5,14 @@
5
5
  * @version 1.0.0-beta.1
6
6
  */
7
7
 
8
- import { NextApiRequest, NextApiResponse, NextPage, GetServerSideProps, GetStaticProps } from 'next';
9
- import { CoherentNode } from '@coherent/core';
8
+ import {
9
+ NextApiRequest,
10
+ NextApiResponse,
11
+ NextPage,
12
+ GetServerSideProps,
13
+ GetStaticProps
14
+ } from 'next';
15
+ import { CoherentNode, RenderOptions } from '@coherent.js/core';
10
16
 
11
17
  // ============================================================================
12
18
  // Next.js Integration Types
@@ -44,7 +50,7 @@ export interface CoherentApiRequest extends NextApiRequest {
44
50
  /** Enhanced Next.js API response */
45
51
  export interface CoherentApiResponse extends NextApiResponse {
46
52
  sendComponent<P = any>(component: (props: P) => CoherentNode, props?: P): void;
47
- renderCoherent(component: CoherentNode, options?: any): void;
53
+ renderCoherent(component: CoherentNode, options?: RenderOptions): void;
48
54
  }
49
55
 
50
56
  // ============================================================================
@@ -116,7 +122,10 @@ export interface NextSSRContext {
116
122
  /** Enhanced GetServerSideProps with Coherent.js support */
117
123
  export type CoherentGetServerSideProps<P = CoherentPageProps> = (
118
124
  context: NextSSRContext & {
119
- renderComponent: <CP = any>(component: (props: CP) => CoherentNode, props?: CP) => string;
125
+ renderComponent: <CP = any>(
126
+ component: (props: CP) => CoherentNode,
127
+ props?: CP
128
+ ) => string;
120
129
  coherentState: any;
121
130
  setCoherentState: (state: any) => void;
122
131
  }
@@ -136,7 +145,10 @@ export type CoherentGetStaticProps<P = CoherentPageProps> = (
136
145
  locales?: string[];
137
146
  defaultLocale?: string;
138
147
  } & {
139
- renderComponent: <CP = any>(component: (props: CP) => CoherentNode, props?: CP) => string;
148
+ renderComponent: <CP = any>(
149
+ component: (props: CP) => CoherentNode,
150
+ props?: CP
151
+ ) => string;
140
152
  }
141
153
  ) => Promise<{
142
154
  props: P;
@@ -172,7 +184,18 @@ export interface ApiMiddlewareOptions {
172
184
  };
173
185
  }
174
186
 
175
- /** API route handler with Coherent.js support */
187
+ /**
188
+ * API route handler with Coherent.js support.
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * import { coherentApiHandler } from '@coherent.js/nextjs';
193
+ *
194
+ * export default coherentApiHandler((req, res) => {
195
+ * res.renderCoherent({ div: { text: 'Hello from API' } });
196
+ * });
197
+ * ```
198
+ */
176
199
  export type CoherentApiHandler = (
177
200
  req: CoherentApiRequest,
178
201
  res: CoherentApiResponse
@@ -246,7 +269,22 @@ export interface BuildStats {
246
269
  // Main Functions
247
270
  // ============================================================================
248
271
 
249
- /** Create Coherent.js Next.js configuration */
272
+ /**
273
+ * Create Coherent.js Next.js configuration.
274
+ *
275
+ * @example
276
+ * ```typescript
277
+ * // next.config.js
278
+ * const { withCoherent } = require('@coherent.js/nextjs');
279
+ *
280
+ * module.exports = withCoherent({
281
+ * coherent: {
282
+ * ssr: true,
283
+ * hydration: true
284
+ * }
285
+ * });
286
+ * ```
287
+ */
250
288
  export function withCoherent(nextConfig?: any): CoherentNextConfig;
251
289
 
252
290
  /** Create page component with Coherent.js support */
@@ -265,6 +303,21 @@ export function createApiRoute(
265
303
  options?: ApiMiddlewareOptions
266
304
  ): CoherentApiHandler;
267
305
 
306
+ /**
307
+ * Wrap an API handler with Coherent.js rendering support.
308
+ *
309
+ * @example
310
+ * ```typescript
311
+ * import { coherentApiHandler } from '@coherent.js/nextjs';
312
+ *
313
+ * export default coherentApiHandler((req, res) => {
314
+ * const component = { div: { text: `Hello ${req.query.name}` } };
315
+ * res.renderCoherent(component);
316
+ * });
317
+ * ```
318
+ */
319
+ export function coherentApiHandler(handler: CoherentApiHandler): CoherentApiHandler;
320
+
268
321
  /** Create layout component */
269
322
  export function createLayout(
270
323
  component: (props: LayoutProps) => CoherentNode
@@ -286,11 +339,44 @@ export function withServerSideProps<P = CoherentPageProps>(
286
339
  getProps: CoherentGetServerSideProps<P>
287
340
  ): GetServerSideProps<P>;
288
341
 
342
+ /**
343
+ * Wrap getServerSideProps with Coherent.js rendering utilities.
344
+ *
345
+ * @example
346
+ * ```typescript
347
+ * import { withCoherentProps } from '@coherent.js/nextjs';
348
+ *
349
+ * export const getServerSideProps = withCoherentProps(async (ctx) => {
350
+ * return {
351
+ * props: {
352
+ * title: 'My Page',
353
+ * content: ctx.renderComponent(MyComponent, { data })
354
+ * }
355
+ * };
356
+ * });
357
+ * ```
358
+ */
359
+ export function withCoherentProps<P = CoherentPageProps>(
360
+ getProps: CoherentGetServerSideProps<P>
361
+ ): GetServerSideProps<P>;
362
+
289
363
  /** Enhanced GetStaticProps */
290
364
  export function withStaticProps<P = CoherentPageProps>(
291
365
  getProps: CoherentGetStaticProps<P>
292
366
  ): GetStaticProps<P>;
293
367
 
368
+ /**
369
+ * Render a CoherentNode to HTML string.
370
+ *
371
+ * @example
372
+ * ```typescript
373
+ * import { renderToString } from '@coherent.js/nextjs';
374
+ *
375
+ * const html = renderToString({ div: { text: 'Hello' } });
376
+ * ```
377
+ */
378
+ export function renderToString(component: CoherentNode, options?: RenderOptions): string;
379
+
294
380
  // ============================================================================
295
381
  // Utility Functions
296
382
  // ============================================================================
@@ -315,11 +401,14 @@ declare const coherentNext: {
315
401
  withCoherent: typeof withCoherent;
316
402
  createPage: typeof createPage;
317
403
  createApiRoute: typeof createApiRoute;
404
+ coherentApiHandler: typeof coherentApiHandler;
318
405
  createLayout: typeof createLayout;
319
406
  createApp: typeof createApp;
320
407
  withMiddleware: typeof withMiddleware;
321
408
  withServerSideProps: typeof withServerSideProps;
409
+ withCoherentProps: typeof withCoherentProps;
322
410
  withStaticProps: typeof withStaticProps;
411
+ renderToString: typeof renderToString;
323
412
  getBuildConfig: typeof getBuildConfig;
324
413
  getRuntimeConfig: typeof getRuntimeConfig;
325
414
  createWebpackConfig: typeof createWebpackConfig;