react-layout-sdk 1.1.8 → 1.1.9

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