react-layout-sdk 1.1.8 → 1.1.10

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/dist/index.d.mts CHANGED
@@ -34,6 +34,35 @@ interface JDLayoutProps {
34
34
  */
35
35
  declare const JDLayout: React.FC<JDLayoutProps>;
36
36
 
37
+ interface JDPageProps {
38
+ params: Promise<{
39
+ slug?: string[];
40
+ }>;
41
+ apiUrl: string;
42
+ componentMap: Record<string, React.ComponentType<any>>;
43
+ supportedLocales?: string[];
44
+ defaultLocale?: string;
45
+ notFoundComponent?: React.ReactNode;
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
+ }>;
54
+ }
55
+ declare const JDPage: ({ params, apiUrl, componentMap, supportedLocales, defaultLocale, notFoundComponent, maintenanceComponent, layoutComponent: LayoutWrapper }: JDPageProps) => Promise<React.JSX.Element>;
56
+ declare const generateJDMetadata: (params: Promise<{
57
+ slug?: string[];
58
+ }>, apiUrl: string, supportedLocales?: string[], defaultLocale?: string) => Promise<{
59
+ title: string;
60
+ description: string | undefined;
61
+ } | {
62
+ title: string;
63
+ description?: undefined;
64
+ }>;
65
+
37
66
  interface JDPlaceholderData {
38
67
  __component: string;
39
68
  [key: string]: any;
@@ -64,4 +93,4 @@ interface JDLayoutResponse {
64
93
  }
65
94
  declare const fetchJDLayout: (apiUrl: string, slug: string, locale?: string, options?: RequestInit) => Promise<JDLayoutResponse | null>;
66
95
 
67
- export { ComponentFactory, type ComponentFactoryProps, type JDContext, JDLayout, type JDLayoutProps, type JDLayoutResponse, type JDPlaceholderData, type JDRoute, Placeholder, type PlaceholderProps, fetchJDLayout };
96
+ export { ComponentFactory, type ComponentFactoryProps, type JDContext, JDLayout, type JDLayoutProps, type JDLayoutResponse, JDPage, type JDPageProps, type JDPlaceholderData, type JDRoute, Placeholder, type PlaceholderProps, fetchJDLayout, generateJDMetadata };
package/dist/index.d.ts CHANGED
@@ -34,6 +34,35 @@ interface JDLayoutProps {
34
34
  */
35
35
  declare const JDLayout: React.FC<JDLayoutProps>;
36
36
 
37
+ interface JDPageProps {
38
+ params: Promise<{
39
+ slug?: string[];
40
+ }>;
41
+ apiUrl: string;
42
+ componentMap: Record<string, React.ComponentType<any>>;
43
+ supportedLocales?: string[];
44
+ defaultLocale?: string;
45
+ notFoundComponent?: React.ReactNode;
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
+ }>;
54
+ }
55
+ declare const JDPage: ({ params, apiUrl, componentMap, supportedLocales, defaultLocale, notFoundComponent, maintenanceComponent, layoutComponent: LayoutWrapper }: JDPageProps) => Promise<React.JSX.Element>;
56
+ declare const generateJDMetadata: (params: Promise<{
57
+ slug?: string[];
58
+ }>, apiUrl: string, supportedLocales?: string[], defaultLocale?: string) => Promise<{
59
+ title: string;
60
+ description: string | undefined;
61
+ } | {
62
+ title: string;
63
+ description?: undefined;
64
+ }>;
65
+
37
66
  interface JDPlaceholderData {
38
67
  __component: string;
39
68
  [key: string]: any;
@@ -64,4 +93,4 @@ interface JDLayoutResponse {
64
93
  }
65
94
  declare const fetchJDLayout: (apiUrl: string, slug: string, locale?: string, options?: RequestInit) => Promise<JDLayoutResponse | null>;
66
95
 
67
- export { ComponentFactory, type ComponentFactoryProps, type JDContext, JDLayout, type JDLayoutProps, type JDLayoutResponse, type JDPlaceholderData, type JDRoute, Placeholder, type PlaceholderProps, fetchJDLayout };
96
+ export { ComponentFactory, type ComponentFactoryProps, type JDContext, JDLayout, type JDLayoutProps, type JDLayoutResponse, JDPage, type JDPageProps, type JDPlaceholderData, type JDRoute, Placeholder, type PlaceholderProps, fetchJDLayout, generateJDMetadata };
package/dist/index.js CHANGED
@@ -32,8 +32,10 @@ var index_exports = {};
32
32
  __export(index_exports, {
33
33
  ComponentFactory: () => ComponentFactory,
34
34
  JDLayout: () => JDLayout,
35
+ JDPage: () => JDPage,
35
36
  Placeholder: () => Placeholder,
36
- fetchJDLayout: () => fetchJDLayout
37
+ fetchJDLayout: () => fetchJDLayout,
38
+ generateJDMetadata: () => generateJDMetadata
37
39
  });
38
40
  module.exports = __toCommonJS(index_exports);
39
41
 
@@ -101,6 +103,66 @@ var JDLayout = ({ layoutData, placeholderComponent: Placeholder2 }) => {
101
103
  )), /* @__PURE__ */ import_react2.default.createElement("main", { className: "grow", style: { flexGrow: 1 } }, /* @__PURE__ */ import_react2.default.createElement(Placeholder2, { name: "main", rendering: route.placeholders.main || [] })), /* @__PURE__ */ import_react2.default.createElement("footer", null, /* @__PURE__ */ import_react2.default.createElement(Placeholder2, { name: "footer", rendering: route.placeholders.footer || [] })));
102
104
  };
103
105
 
106
+ // src/Page.tsx
107
+ var import_react3 = __toESM(require("react"));
108
+ var JDPage = async ({
109
+ params,
110
+ apiUrl,
111
+ componentMap,
112
+ supportedLocales = ["en"],
113
+ defaultLocale = "en",
114
+ notFoundComponent = /* @__PURE__ */ import_react3.default.createElement("h1", null, "404 - Not Found"),
115
+ maintenanceComponent = /* @__PURE__ */ import_react3.default.createElement("h1", null, "Error Loading Layout"),
116
+ layoutComponent: LayoutWrapper = JDLayout
117
+ }) => {
118
+ const resolvedParams = await params;
119
+ const slugArray = resolvedParams?.slug || [];
120
+ let currentLocale = defaultLocale;
121
+ let layoutSlug = [...slugArray];
122
+ if (layoutSlug.length > 0 && supportedLocales.includes(layoutSlug[0])) {
123
+ currentLocale = layoutSlug[0];
124
+ layoutSlug = layoutSlug.slice(1);
125
+ }
126
+ const path = layoutSlug.join("/") || "home";
127
+ try {
128
+ const layoutData = await fetchJDLayout(apiUrl, path, currentLocale);
129
+ if (!layoutData || !layoutData.strapi) {
130
+ return /* @__PURE__ */ import_react3.default.createElement(import_react3.default.Fragment, null, notFoundComponent);
131
+ }
132
+ const CustomPlaceholder = (props) => /* @__PURE__ */ import_react3.default.createElement(Placeholder, { ...props, componentMap });
133
+ return /* @__PURE__ */ import_react3.default.createElement(LayoutWrapper, { layoutData, placeholderComponent: CustomPlaceholder });
134
+ } catch (error) {
135
+ console.error("[JD SDK] JDPage Error:", error);
136
+ return /* @__PURE__ */ import_react3.default.createElement(import_react3.default.Fragment, null, maintenanceComponent);
137
+ }
138
+ };
139
+ var generateJDMetadata = async (params, apiUrl, supportedLocales = ["en"], defaultLocale = "en") => {
140
+ const resolvedParams = await params;
141
+ const slugArray = resolvedParams?.slug || [];
142
+ let currentLocale = defaultLocale;
143
+ let layoutSlug = [...slugArray];
144
+ if (layoutSlug.length > 0 && supportedLocales.includes(layoutSlug[0])) {
145
+ currentLocale = layoutSlug[0];
146
+ layoutSlug = layoutSlug.slice(1);
147
+ }
148
+ const path = layoutSlug.join("/") || "home";
149
+ try {
150
+ const layoutData = await fetchJDLayout(apiUrl, path, currentLocale);
151
+ if (layoutData?.strapi?.route?.seo) {
152
+ const { metaTitle, metaDescription } = layoutData.strapi.route.seo;
153
+ return {
154
+ title: metaTitle || layoutData.strapi.route.displayName,
155
+ description: metaDescription
156
+ };
157
+ }
158
+ return {
159
+ title: layoutData?.strapi?.route?.displayName || ""
160
+ };
161
+ } catch (error) {
162
+ return { title: "" };
163
+ }
164
+ };
165
+
104
166
  // src/index.ts
105
167
  var fetchJDLayout = async (apiUrl, slug, locale = "en", options) => {
106
168
  try {
@@ -122,6 +184,8 @@ var fetchJDLayout = async (apiUrl, slug, locale = "en", options) => {
122
184
  0 && (module.exports = {
123
185
  ComponentFactory,
124
186
  JDLayout,
187
+ JDPage,
125
188
  Placeholder,
126
- fetchJDLayout
189
+ fetchJDLayout,
190
+ generateJDMetadata
127
191
  });
package/dist/index.mjs CHANGED
@@ -62,6 +62,66 @@ var JDLayout = ({ layoutData, placeholderComponent: Placeholder2 }) => {
62
62
  )), /* @__PURE__ */ React2.createElement("main", { className: "grow", style: { flexGrow: 1 } }, /* @__PURE__ */ React2.createElement(Placeholder2, { name: "main", rendering: route.placeholders.main || [] })), /* @__PURE__ */ React2.createElement("footer", null, /* @__PURE__ */ React2.createElement(Placeholder2, { name: "footer", rendering: route.placeholders.footer || [] })));
63
63
  };
64
64
 
65
+ // src/Page.tsx
66
+ import React3 from "react";
67
+ var JDPage = async ({
68
+ params,
69
+ apiUrl,
70
+ componentMap,
71
+ supportedLocales = ["en"],
72
+ defaultLocale = "en",
73
+ notFoundComponent = /* @__PURE__ */ React3.createElement("h1", null, "404 - Not Found"),
74
+ maintenanceComponent = /* @__PURE__ */ React3.createElement("h1", null, "Error Loading Layout"),
75
+ layoutComponent: LayoutWrapper = JDLayout
76
+ }) => {
77
+ const resolvedParams = await params;
78
+ const slugArray = resolvedParams?.slug || [];
79
+ let currentLocale = defaultLocale;
80
+ let layoutSlug = [...slugArray];
81
+ if (layoutSlug.length > 0 && supportedLocales.includes(layoutSlug[0])) {
82
+ currentLocale = layoutSlug[0];
83
+ layoutSlug = layoutSlug.slice(1);
84
+ }
85
+ const path = layoutSlug.join("/") || "home";
86
+ try {
87
+ const layoutData = await fetchJDLayout(apiUrl, path, currentLocale);
88
+ if (!layoutData || !layoutData.strapi) {
89
+ return /* @__PURE__ */ React3.createElement(React3.Fragment, null, notFoundComponent);
90
+ }
91
+ const CustomPlaceholder = (props) => /* @__PURE__ */ React3.createElement(Placeholder, { ...props, componentMap });
92
+ return /* @__PURE__ */ React3.createElement(LayoutWrapper, { layoutData, placeholderComponent: CustomPlaceholder });
93
+ } catch (error) {
94
+ console.error("[JD SDK] JDPage Error:", error);
95
+ return /* @__PURE__ */ React3.createElement(React3.Fragment, null, maintenanceComponent);
96
+ }
97
+ };
98
+ var generateJDMetadata = async (params, apiUrl, supportedLocales = ["en"], defaultLocale = "en") => {
99
+ const resolvedParams = await params;
100
+ const slugArray = resolvedParams?.slug || [];
101
+ let currentLocale = defaultLocale;
102
+ let layoutSlug = [...slugArray];
103
+ if (layoutSlug.length > 0 && supportedLocales.includes(layoutSlug[0])) {
104
+ currentLocale = layoutSlug[0];
105
+ layoutSlug = layoutSlug.slice(1);
106
+ }
107
+ const path = layoutSlug.join("/") || "home";
108
+ try {
109
+ const layoutData = await fetchJDLayout(apiUrl, path, currentLocale);
110
+ if (layoutData?.strapi?.route?.seo) {
111
+ const { metaTitle, metaDescription } = layoutData.strapi.route.seo;
112
+ return {
113
+ title: metaTitle || layoutData.strapi.route.displayName,
114
+ description: metaDescription
115
+ };
116
+ }
117
+ return {
118
+ title: layoutData?.strapi?.route?.displayName || ""
119
+ };
120
+ } catch (error) {
121
+ return { title: "" };
122
+ }
123
+ };
124
+
65
125
  // src/index.ts
66
126
  var fetchJDLayout = async (apiUrl, slug, locale = "en", options) => {
67
127
  try {
@@ -82,6 +142,8 @@ var fetchJDLayout = async (apiUrl, slug, locale = "en", options) => {
82
142
  export {
83
143
  ComponentFactory,
84
144
  JDLayout,
145
+ JDPage,
85
146
  Placeholder,
86
- fetchJDLayout
147
+ fetchJDLayout,
148
+ generateJDMetadata
87
149
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-layout-sdk",
3
- "version": "1.1.8",
3
+ "version": "1.1.10",
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 ADDED
@@ -0,0 +1,94 @@
1
+ import React from 'react';
2
+ import { fetchJDLayout } from './index';
3
+ import { JDLayout } from './Layout';
4
+ import { Placeholder } from './Placeholder';
5
+
6
+ export interface JDPageProps {
7
+ params: Promise<{ slug?: string[] }>;
8
+ apiUrl: string;
9
+ componentMap: Record<string, React.ComponentType<any>>;
10
+ supportedLocales?: string[];
11
+ defaultLocale?: string;
12
+ notFoundComponent?: React.ReactNode;
13
+ maintenanceComponent?: React.ReactNode;
14
+ /**
15
+ * Optional custom layout component. If not provided, uses JDLayout.
16
+ */
17
+ layoutComponent?: React.ComponentType<{ layoutData: any; placeholderComponent: any }>;
18
+ }
19
+
20
+ export const JDPage = async ({
21
+ params,
22
+ apiUrl,
23
+ componentMap,
24
+ supportedLocales = ['en'],
25
+ defaultLocale = 'en',
26
+ notFoundComponent = <h1>404 - Not Found</h1>,
27
+ maintenanceComponent = <h1>Error Loading Layout</h1>,
28
+ layoutComponent: LayoutWrapper = JDLayout
29
+ }: JDPageProps) => {
30
+ const resolvedParams = await params;
31
+ const slugArray = resolvedParams?.slug || [];
32
+
33
+ let currentLocale = defaultLocale;
34
+ let layoutSlug = [...slugArray];
35
+
36
+ if (layoutSlug.length > 0 && supportedLocales.includes(layoutSlug[0])) {
37
+ currentLocale = layoutSlug[0];
38
+ layoutSlug = layoutSlug.slice(1);
39
+ }
40
+
41
+ const path = layoutSlug.join('/') || 'home';
42
+
43
+ try {
44
+ const layoutData = await fetchJDLayout(apiUrl, path, currentLocale);
45
+ if (!layoutData || !layoutData.strapi) {
46
+ return <>{notFoundComponent}</>;
47
+ }
48
+
49
+ const CustomPlaceholder = (props: any) => (
50
+ <Placeholder {...props} componentMap={componentMap} />
51
+ );
52
+
53
+ return <LayoutWrapper layoutData={layoutData} placeholderComponent={CustomPlaceholder} />;
54
+ } catch (error) {
55
+ console.error('[JD SDK] JDPage Error:', error);
56
+ return <>{maintenanceComponent}</>;
57
+ }
58
+ };
59
+
60
+ export const generateJDMetadata = async (
61
+ params: Promise<{ slug?: string[] }>,
62
+ apiUrl: string,
63
+ supportedLocales: string[] = ['en'],
64
+ defaultLocale: string = 'en'
65
+ ) => {
66
+ const resolvedParams = await params;
67
+ const slugArray = resolvedParams?.slug || [];
68
+
69
+ let currentLocale = defaultLocale;
70
+ let layoutSlug = [...slugArray];
71
+
72
+ if (layoutSlug.length > 0 && supportedLocales.includes(layoutSlug[0])) {
73
+ currentLocale = layoutSlug[0];
74
+ layoutSlug = layoutSlug.slice(1);
75
+ }
76
+
77
+ const path = layoutSlug.join('/') || 'home';
78
+
79
+ try {
80
+ const layoutData = await fetchJDLayout(apiUrl, path, currentLocale);
81
+ if (layoutData?.strapi?.route?.seo) {
82
+ const { metaTitle, metaDescription } = layoutData.strapi.route.seo;
83
+ return {
84
+ title: metaTitle || layoutData.strapi.route.displayName,
85
+ description: metaDescription,
86
+ };
87
+ }
88
+ return {
89
+ title: layoutData?.strapi?.route?.displayName || "",
90
+ };
91
+ } catch (error) {
92
+ return { title: '' };
93
+ }
94
+ };
package/src/index.ts CHANGED
@@ -2,6 +2,8 @@ export { Placeholder, ComponentFactory } from './Placeholder';
2
2
  export type { PlaceholderProps, ComponentFactoryProps } from './Placeholder';
3
3
  export { JDLayout } from './Layout';
4
4
  export type { JDLayoutProps } from './Layout';
5
+ export { JDPage, generateJDMetadata } from './Page';
6
+ export type { JDPageProps } from './Page';
5
7
 
6
8
  // Useful type definitions for the API response
7
9
  export interface JDPlaceholderData {