react-layout-sdk 1.1.7 → 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
@@ -16,6 +16,46 @@ interface PlaceholderProps {
16
16
  }
17
17
  declare const Placeholder: React.FC<PlaceholderProps>;
18
18
 
19
+ interface JDLayoutProps {
20
+ layoutData: JDLayoutResponse;
21
+ /**
22
+ * The Placeholder component from your application's Component Factory.
23
+ * This is required because your application defines the actual React components.
24
+ */
25
+ placeholderComponent: React.ComponentType<{
26
+ name: string;
27
+ rendering: any[];
28
+ customProps?: any;
29
+ }>;
30
+ }
31
+ /**
32
+ * A generic Layout component that provides the standard Header, Main, and Footer placeholders.
33
+ * Uses Tailwind CSS classes by default, with inline styles as fallbacks.
34
+ */
35
+ declare const JDLayout: React.FC<JDLayoutProps>;
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
+
19
59
  interface JDPlaceholderData {
20
60
  __component: string;
21
61
  [key: string]: any;
@@ -46,4 +86,4 @@ interface JDLayoutResponse {
46
86
  }
47
87
  declare const fetchJDLayout: (apiUrl: string, slug: string, locale?: string, options?: RequestInit) => Promise<JDLayoutResponse | null>;
48
88
 
49
- export { ComponentFactory, type ComponentFactoryProps, type JDContext, 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
@@ -16,6 +16,46 @@ interface PlaceholderProps {
16
16
  }
17
17
  declare const Placeholder: React.FC<PlaceholderProps>;
18
18
 
19
+ interface JDLayoutProps {
20
+ layoutData: JDLayoutResponse;
21
+ /**
22
+ * The Placeholder component from your application's Component Factory.
23
+ * This is required because your application defines the actual React components.
24
+ */
25
+ placeholderComponent: React.ComponentType<{
26
+ name: string;
27
+ rendering: any[];
28
+ customProps?: any;
29
+ }>;
30
+ }
31
+ /**
32
+ * A generic Layout component that provides the standard Header, Main, and Footer placeholders.
33
+ * Uses Tailwind CSS classes by default, with inline styles as fallbacks.
34
+ */
35
+ declare const JDLayout: React.FC<JDLayoutProps>;
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
+
19
59
  interface JDPlaceholderData {
20
60
  __component: string;
21
61
  [key: string]: any;
@@ -46,4 +86,4 @@ interface JDLayoutResponse {
46
86
  }
47
87
  declare const fetchJDLayout: (apiUrl: string, slug: string, locale?: string, options?: RequestInit) => Promise<JDLayoutResponse | null>;
48
88
 
49
- export { ComponentFactory, type ComponentFactoryProps, type JDContext, 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
@@ -31,8 +31,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  ComponentFactory: () => ComponentFactory,
34
+ JDLayout: () => JDLayout,
35
+ JDPage: () => JDPage,
34
36
  Placeholder: () => Placeholder,
35
- fetchJDLayout: () => fetchJDLayout
37
+ fetchJDLayout: () => fetchJDLayout,
38
+ generateJDMetadata: () => generateJDMetadata
36
39
  });
37
40
  module.exports = __toCommonJS(index_exports);
38
41
 
@@ -86,6 +89,79 @@ var Placeholder = ({ name, rendering, customProps, componentMap }) => {
86
89
  )));
87
90
  };
88
91
 
92
+ // src/Layout.tsx
93
+ var import_react2 = __toESM(require("react"));
94
+ var JDLayout = ({ layoutData, placeholderComponent: Placeholder2 }) => {
95
+ const { route, context } = layoutData.strapi;
96
+ return /* @__PURE__ */ import_react2.default.createElement("div", { className: "flex flex-col min-h-screen", style: { display: "flex", flexDirection: "column", minHeight: "100vh" } }, /* @__PURE__ */ import_react2.default.createElement("header", null, /* @__PURE__ */ import_react2.default.createElement(
97
+ Placeholder2,
98
+ {
99
+ name: "header",
100
+ rendering: route.placeholders.header || [],
101
+ customProps: { locales: context.locales, currentLocale: context.language }
102
+ }
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 || [] })));
104
+ };
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
+
89
165
  // src/index.ts
90
166
  var fetchJDLayout = async (apiUrl, slug, locale = "en", options) => {
91
167
  try {
@@ -106,6 +182,9 @@ var fetchJDLayout = async (apiUrl, slug, locale = "en", options) => {
106
182
  // Annotate the CommonJS export names for ESM import in node:
107
183
  0 && (module.exports = {
108
184
  ComponentFactory,
185
+ JDLayout,
186
+ JDPage,
109
187
  Placeholder,
110
- fetchJDLayout
188
+ fetchJDLayout,
189
+ generateJDMetadata
111
190
  });
package/dist/index.mjs CHANGED
@@ -48,6 +48,79 @@ var Placeholder = ({ name, rendering, customProps, componentMap }) => {
48
48
  )));
49
49
  };
50
50
 
51
+ // src/Layout.tsx
52
+ import React2 from "react";
53
+ var JDLayout = ({ layoutData, placeholderComponent: Placeholder2 }) => {
54
+ const { route, context } = layoutData.strapi;
55
+ return /* @__PURE__ */ React2.createElement("div", { className: "flex flex-col min-h-screen", style: { display: "flex", flexDirection: "column", minHeight: "100vh" } }, /* @__PURE__ */ React2.createElement("header", null, /* @__PURE__ */ React2.createElement(
56
+ Placeholder2,
57
+ {
58
+ name: "header",
59
+ rendering: route.placeholders.header || [],
60
+ customProps: { locales: context.locales, currentLocale: context.language }
61
+ }
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
+ };
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
+
51
124
  // src/index.ts
52
125
  var fetchJDLayout = async (apiUrl, slug, locale = "en", options) => {
53
126
  try {
@@ -67,6 +140,9 @@ var fetchJDLayout = async (apiUrl, slug, locale = "en", options) => {
67
140
  };
68
141
  export {
69
142
  ComponentFactory,
143
+ JDLayout,
144
+ JDPage,
70
145
  Placeholder,
71
- fetchJDLayout
146
+ fetchJDLayout,
147
+ generateJDMetadata
72
148
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-layout-sdk",
3
- "version": "1.1.7",
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/Layout.tsx ADDED
@@ -0,0 +1,39 @@
1
+ import React from 'react';
2
+ import { JDLayoutResponse } from './index';
3
+
4
+ export interface JDLayoutProps {
5
+ layoutData: JDLayoutResponse;
6
+ /**
7
+ * The Placeholder component from your application's Component Factory.
8
+ * This is required because your application defines the actual React components.
9
+ */
10
+ placeholderComponent: React.ComponentType<{ name: string; rendering: any[]; customProps?: any }>;
11
+ }
12
+
13
+ /**
14
+ * A generic Layout component that provides the standard Header, Main, and Footer placeholders.
15
+ * Uses Tailwind CSS classes by default, with inline styles as fallbacks.
16
+ */
17
+ export const JDLayout: React.FC<JDLayoutProps> = ({ layoutData, placeholderComponent: Placeholder }) => {
18
+ const { route, context } = layoutData.strapi;
19
+
20
+ return (
21
+ <div className="flex flex-col min-h-screen" style={{ display: 'flex', flexDirection: 'column', minHeight: '100vh' }}>
22
+ <header>
23
+ <Placeholder
24
+ name="header"
25
+ rendering={route.placeholders.header || []}
26
+ customProps={{ locales: context.locales, currentLocale: context.language }}
27
+ />
28
+ </header>
29
+
30
+ <main className="grow" style={{ flexGrow: 1 }}>
31
+ <Placeholder name="main" rendering={route.placeholders.main || []} />
32
+ </main>
33
+
34
+ <footer>
35
+ <Placeholder name="footer" rendering={route.placeholders.footer || []} />
36
+ </footer>
37
+ </div>
38
+ );
39
+ };
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
@@ -1,5 +1,9 @@
1
1
  export { Placeholder, ComponentFactory } from './Placeholder';
2
2
  export type { PlaceholderProps, ComponentFactoryProps } from './Placeholder';
3
+ export { JDLayout } from './Layout';
4
+ export type { JDLayoutProps } from './Layout';
5
+ export { JDPage, generateJDMetadata } from './Page';
6
+ export type { JDPageProps } from './Page';
3
7
 
4
8
  // Useful type definitions for the API response
5
9
  export interface JDPlaceholderData {