react-layout-sdk 1.1.9 → 1.1.11

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/bin/init.js CHANGED
@@ -157,7 +157,7 @@ if (command === 'init') {
157
157
  ensureDirSync(pageDir);
158
158
 
159
159
  const appPagePath = path.join(pageDir, 'page.tsx');
160
- const appPageContent = `import React from 'react';\nimport { fetchJDLayout, Placeholder } from 'react-layout-sdk';\nimport { componentMap } from '@/components/factory';\n\nexport default async function Page({ params }: { params: Promise<{ slug?: string[] }> }) {\n const resolvedParams = await params;\n const slugArray = resolvedParams?.slug || [];\n const path = slugArray.join('/') || '/';\n const STRAPI_URL = process.env.NEXT_PUBLIC_STRAPI_URL || 'http://localhost:1337';\n \n try {\n const layoutData = await fetchJDLayout(STRAPI_URL, path, 'en');\n if (!layoutData || !layoutData.strapi) return <h1>404 - Not Found</h1>;\n\n const { route } = layoutData.strapi;\n\n return (\n <div className="layout-wrapper">\n <Placeholder name="header" rendering={route.placeholders.header || []} componentMap={componentMap} />\n <main style={{ minHeight: '60vh', padding: '20px' }}>\n <Placeholder name="main" rendering={route.placeholders.main || []} componentMap={componentMap} />\n </main>\n <Placeholder name="footer" rendering={route.placeholders.footer || []} componentMap={componentMap} />\n </div>\n );\n } catch (error) {\n return <h1>Error Loading Layout</h1>;\n }\n}\n`;
160
+ const appPageContent = `import React from 'react';\nimport { JDPage, generateJDMetadata } from 'react-layout-sdk';\nimport { componentMap } from '@/components/factory';\n\nconst STRAPI_URL = process.env.NEXT_PUBLIC_STRAPI_URL || 'http://localhost:1337';\n\nexport const generateMetadata = ({ params }: { params: Promise<{ slug?: string[] }> }) => {\n return generateJDMetadata(params, STRAPI_URL);\n}\n\nexport default function Page({ params }: { params: Promise<{ slug?: string[] }> }) {\n return <JDPage params={params} apiUrl={STRAPI_URL} componentMap={componentMap} />;\n}\n`;
161
161
  if (!fs.existsSync(appPagePath)) {
162
162
  fs.writeFileSync(appPagePath, appPageContent);
163
163
  console.log('✅ Created app/[[...slug]]/page.tsx');
@@ -173,7 +173,7 @@ if (command === 'init') {
173
173
  }
174
174
 
175
175
  const pagePath = path.join(basePath, 'pages', '[[...slug]].tsx');
176
- const pagesContent = `import React from 'react';\nimport { fetchJDLayout, Placeholder } from 'react-layout-sdk';\nimport { componentMap } from '@/components/factory';\n\nexport default function LayoutPage({ layoutData, error }: any) {\n if (error || !layoutData?.strapi) return <h1>404 - Layout Not Found</h1>;\n\n const { route } = layoutData.strapi;\n return (\n <div className="layout-wrapper">\n <Placeholder name="header" rendering={route.placeholders.header || []} componentMap={componentMap} />\n <main style={{ minHeight: '60vh', padding: '20px' }}>\n <Placeholder name="main" rendering={route.placeholders.main || []} componentMap={componentMap} />\n </main>\n <Placeholder name="footer" rendering={route.placeholders.footer || []} componentMap={componentMap} />\n </div>\n );\n}\n\nexport async function getServerSideProps(context: any) {\n const slugArray = context.params?.slug || [];\n const path = slugArray.join('/') || '/';\n const STRAPI_URL = process.env.NEXT_PUBLIC_STRAPI_URL || 'http://localhost:1337';\n\n try {\n const layoutData = await fetchJDLayout(STRAPI_URL, path, 'en');\n if (!layoutData) return { notFound: true };\n\n return { props: { layoutData } };\n } catch (error) {\n return { props: { error: true } };\n }\n}\n`;
176
+ const pagesContent = `import React from 'react';\nimport { fetchJDLayout, JDLayout, Placeholder } from 'react-layout-sdk';\nimport { componentMap } from '@/components/factory';\n\nexport default function LayoutPage({ layoutData, error }: any) {\n if (error || !layoutData?.strapi) return <h1>404 - Layout Not Found</h1>;\n\n const CustomPlaceholder = (props: any) => <Placeholder {...props} componentMap={componentMap} />;\n\n return <JDLayout layoutData={layoutData} placeholderComponent={CustomPlaceholder} />;\n}\n\nexport async function getServerSideProps(context: any) {\n const slugArray = context.params?.slug || [];\n const path = slugArray.join('/') || '/';\n const STRAPI_URL = process.env.NEXT_PUBLIC_STRAPI_URL || 'http://localhost:1337';\n\n try {\n const layoutData = await fetchJDLayout(STRAPI_URL, path, 'en');\n if (!layoutData) return { notFound: true };\n\n return { props: { layoutData } };\n } catch (error) {\n return { props: { error: true } };\n }\n}\n`;
177
177
  if (!fs.existsSync(pagePath)) {
178
178
  fs.writeFileSync(pagePath, pagesContent);
179
179
  console.log('✅ Created pages/[[...slug]].tsx');
package/dist/index.d.mts CHANGED
@@ -44,8 +44,15 @@ interface JDPageProps {
44
44
  defaultLocale?: string;
45
45
  notFoundComponent?: React.ReactNode;
46
46
  maintenanceComponent?: React.ReactNode;
47
+ /**
48
+ * Optional custom layout component. If not provided, uses JDLayout.
49
+ */
50
+ layoutComponent?: React.ComponentType<{
51
+ layoutData: any;
52
+ placeholderComponent: any;
53
+ }>;
47
54
  }
48
- declare const JDPage: ({ params, apiUrl, componentMap, supportedLocales, defaultLocale, notFoundComponent, maintenanceComponent }: JDPageProps) => Promise<React.JSX.Element>;
55
+ declare const JDPage: ({ params, apiUrl, componentMap, supportedLocales, defaultLocale, notFoundComponent, maintenanceComponent, layoutComponent: LayoutWrapper }: JDPageProps) => Promise<React.JSX.Element>;
49
56
  declare const generateJDMetadata: (params: Promise<{
50
57
  slug?: string[];
51
58
  }>, apiUrl: string, supportedLocales?: string[], defaultLocale?: string) => Promise<{
package/dist/index.d.ts CHANGED
@@ -44,8 +44,15 @@ interface JDPageProps {
44
44
  defaultLocale?: string;
45
45
  notFoundComponent?: React.ReactNode;
46
46
  maintenanceComponent?: React.ReactNode;
47
+ /**
48
+ * Optional custom layout component. If not provided, uses JDLayout.
49
+ */
50
+ layoutComponent?: React.ComponentType<{
51
+ layoutData: any;
52
+ placeholderComponent: any;
53
+ }>;
47
54
  }
48
- declare const JDPage: ({ params, apiUrl, componentMap, supportedLocales, defaultLocale, notFoundComponent, maintenanceComponent }: JDPageProps) => Promise<React.JSX.Element>;
55
+ declare const JDPage: ({ params, apiUrl, componentMap, supportedLocales, defaultLocale, notFoundComponent, maintenanceComponent, layoutComponent: LayoutWrapper }: JDPageProps) => Promise<React.JSX.Element>;
49
56
  declare const generateJDMetadata: (params: Promise<{
50
57
  slug?: string[];
51
58
  }>, apiUrl: string, supportedLocales?: string[], defaultLocale?: string) => Promise<{
package/dist/index.js CHANGED
@@ -112,7 +112,8 @@ var JDPage = async ({
112
112
  supportedLocales = ["en"],
113
113
  defaultLocale = "en",
114
114
  notFoundComponent = /* @__PURE__ */ import_react3.default.createElement("h1", null, "404 - Not Found"),
115
- maintenanceComponent = /* @__PURE__ */ import_react3.default.createElement("h1", null, "Error Loading Layout")
115
+ maintenanceComponent = /* @__PURE__ */ import_react3.default.createElement("h1", null, "Error Loading Layout"),
116
+ layoutComponent: LayoutWrapper = JDLayout
116
117
  }) => {
117
118
  const resolvedParams = await params;
118
119
  const slugArray = resolvedParams?.slug || [];
@@ -129,7 +130,7 @@ var JDPage = async ({
129
130
  return /* @__PURE__ */ import_react3.default.createElement(import_react3.default.Fragment, null, notFoundComponent);
130
131
  }
131
132
  const CustomPlaceholder = (props) => /* @__PURE__ */ import_react3.default.createElement(Placeholder, { ...props, componentMap });
132
- return /* @__PURE__ */ import_react3.default.createElement(JDLayout, { layoutData, placeholderComponent: CustomPlaceholder });
133
+ return /* @__PURE__ */ import_react3.default.createElement(LayoutWrapper, { layoutData, placeholderComponent: CustomPlaceholder });
133
134
  } catch (error) {
134
135
  console.error("[JD SDK] JDPage Error:", error);
135
136
  return /* @__PURE__ */ import_react3.default.createElement(import_react3.default.Fragment, null, maintenanceComponent);
package/dist/index.mjs CHANGED
@@ -71,7 +71,8 @@ var JDPage = async ({
71
71
  supportedLocales = ["en"],
72
72
  defaultLocale = "en",
73
73
  notFoundComponent = /* @__PURE__ */ React3.createElement("h1", null, "404 - Not Found"),
74
- maintenanceComponent = /* @__PURE__ */ React3.createElement("h1", null, "Error Loading Layout")
74
+ maintenanceComponent = /* @__PURE__ */ React3.createElement("h1", null, "Error Loading Layout"),
75
+ layoutComponent: LayoutWrapper = JDLayout
75
76
  }) => {
76
77
  const resolvedParams = await params;
77
78
  const slugArray = resolvedParams?.slug || [];
@@ -88,7 +89,7 @@ var JDPage = async ({
88
89
  return /* @__PURE__ */ React3.createElement(React3.Fragment, null, notFoundComponent);
89
90
  }
90
91
  const CustomPlaceholder = (props) => /* @__PURE__ */ React3.createElement(Placeholder, { ...props, componentMap });
91
- return /* @__PURE__ */ React3.createElement(JDLayout, { layoutData, placeholderComponent: CustomPlaceholder });
92
+ return /* @__PURE__ */ React3.createElement(LayoutWrapper, { layoutData, placeholderComponent: CustomPlaceholder });
92
93
  } catch (error) {
93
94
  console.error("[JD SDK] JDPage Error:", error);
94
95
  return /* @__PURE__ */ React3.createElement(React3.Fragment, null, maintenanceComponent);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-layout-sdk",
3
- "version": "1.1.9",
3
+ "version": "1.1.11",
4
4
  "description": "React components for JD SDK (Sitecore-like routing)",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/src/Page.tsx CHANGED
@@ -11,6 +11,10 @@ export interface JDPageProps {
11
11
  defaultLocale?: string;
12
12
  notFoundComponent?: React.ReactNode;
13
13
  maintenanceComponent?: React.ReactNode;
14
+ /**
15
+ * Optional custom layout component. If not provided, uses JDLayout.
16
+ */
17
+ layoutComponent?: React.ComponentType<{ layoutData: any; placeholderComponent: any }>;
14
18
  }
15
19
 
16
20
  export const JDPage = async ({
@@ -20,7 +24,8 @@ export const JDPage = async ({
20
24
  supportedLocales = ['en'],
21
25
  defaultLocale = 'en',
22
26
  notFoundComponent = <h1>404 - Not Found</h1>,
23
- maintenanceComponent = <h1>Error Loading Layout</h1>
27
+ maintenanceComponent = <h1>Error Loading Layout</h1>,
28
+ layoutComponent: LayoutWrapper = JDLayout
24
29
  }: JDPageProps) => {
25
30
  const resolvedParams = await params;
26
31
  const slugArray = resolvedParams?.slug || [];
@@ -45,7 +50,7 @@ export const JDPage = async ({
45
50
  <Placeholder {...props} componentMap={componentMap} />
46
51
  );
47
52
 
48
- return <JDLayout layoutData={layoutData} placeholderComponent={CustomPlaceholder} />;
53
+ return <LayoutWrapper layoutData={layoutData} placeholderComponent={CustomPlaceholder} />;
49
54
  } catch (error) {
50
55
  console.error('[JD SDK] JDPage Error:', error);
51
56
  return <>{maintenanceComponent}</>;