react-layout-sdk 1.1.6 → 1.1.8

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/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # React Layout SDK (JD Layout System)
2
+
3
+ The **React Layout SDK** is an enterprise-grade Frontend SDK designed to consume layout definitions from Strapi via the **Strapi Layout Plugin**. Inspired by robust headless ecosystems like Sitecore JSS, this SDK provides dynamic placeholder routing and a scaffold generator to stream-line Developer Experience (DX).
4
+
5
+ ## Installation
6
+
7
+ Install the package using your favorite package manager:
8
+
9
+ ```bash
10
+ npm install react-layout-sdk
11
+ ```
12
+
13
+ ## Quick Start (Project Scaffolding)
14
+
15
+ To quickly set up your Next.js project to work with the JD Layout System, run the init command at the root of your project:
16
+
17
+ ```bash
18
+ npx react-layout-sdk init
19
+ ```
20
+
21
+ **What this does:**
22
+ 1. Creates a `src/components/factory.tsx` file for component mapping.
23
+ 2. Generates base boilerplate components like `Header.tsx` and `Footer.tsx`.
24
+ 3. Auto-configures your Next.js App Router (`app/[[...slug]]/page.tsx`) or Pages Router to catch all layout routes and fetch them dynamically using `fetchJDLayout`.
25
+
26
+ ## Component Scaffolding
27
+
28
+ You can scaffold new React components and automatically map them to their corresponding Strapi components in `factory.tsx` using the generate command:
29
+
30
+ ```bash
31
+ npx react-layout-sdk generate component <strapi-component-uid>
32
+ ```
33
+
34
+ **Example:**
35
+ ```bash
36
+ npx react-layout-sdk generate component blocks.hero-banner
37
+ ```
38
+ *This command will:*
39
+ - Create `src/components/HeroBanner.tsx`.
40
+ - Automatically inject `import HeroBanner` and map `'blocks.hero-banner': HeroBanner` inside your `factory.tsx`.
41
+
42
+ ## API Reference
43
+
44
+ ### 1. `fetchJDLayout(apiUrl, slug, locale)`
45
+ Fetches the layout structure and content from the Strapi backend.
46
+
47
+ ```typescript
48
+ import { fetchJDLayout } from 'react-layout-sdk';
49
+
50
+ const layoutData = await fetchJDLayout('http://localhost:1337', '/home', 'en');
51
+ const { route } = layoutData.strapi;
52
+ ```
53
+
54
+ ### 2. `<Placeholder />`
55
+ Renders a specific dynamic zone (like `header`, `main`, or `footer`) by matching the JSON data against your React components.
56
+
57
+ ```tsx
58
+ import { Placeholder } from 'react-layout-sdk';
59
+ import { componentMap } from '@/components/factory';
60
+
61
+ <main>
62
+ <Placeholder
63
+ name="main"
64
+ rendering={route.placeholders.main || []}
65
+ componentMap={componentMap}
66
+ />
67
+ </main>
68
+ ```
69
+
70
+ ## TypeScript Support
71
+
72
+ This package comes with full TypeScript definitions, including `JDLayoutResponse`, `JDRoute`, and `JDContext`.
package/dist/index.d.mts CHANGED
@@ -16,6 +16,24 @@ 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
+
19
37
  interface JDPlaceholderData {
20
38
  __component: string;
21
39
  [key: string]: any;
@@ -23,6 +41,13 @@ interface JDPlaceholderData {
23
41
  interface JDRoute {
24
42
  name: string;
25
43
  displayName: string;
44
+ fields?: Record<string, any>;
45
+ seo?: {
46
+ metaTitle?: string;
47
+ metaDescription?: string;
48
+ metaImage?: any;
49
+ [key: string]: any;
50
+ };
26
51
  placeholders: Record<string, JDPlaceholderData[]>;
27
52
  }
28
53
  interface JDContext {
@@ -39,4 +64,4 @@ interface JDLayoutResponse {
39
64
  }
40
65
  declare const fetchJDLayout: (apiUrl: string, slug: string, locale?: string, options?: RequestInit) => Promise<JDLayoutResponse | null>;
41
66
 
42
- export { ComponentFactory, type ComponentFactoryProps, type JDContext, type JDLayoutResponse, type JDPlaceholderData, type JDRoute, Placeholder, type PlaceholderProps, fetchJDLayout };
67
+ export { ComponentFactory, type ComponentFactoryProps, type JDContext, JDLayout, type JDLayoutProps, type JDLayoutResponse, type JDPlaceholderData, type JDRoute, Placeholder, type PlaceholderProps, fetchJDLayout };
package/dist/index.d.ts CHANGED
@@ -16,6 +16,24 @@ 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
+
19
37
  interface JDPlaceholderData {
20
38
  __component: string;
21
39
  [key: string]: any;
@@ -23,6 +41,13 @@ interface JDPlaceholderData {
23
41
  interface JDRoute {
24
42
  name: string;
25
43
  displayName: string;
44
+ fields?: Record<string, any>;
45
+ seo?: {
46
+ metaTitle?: string;
47
+ metaDescription?: string;
48
+ metaImage?: any;
49
+ [key: string]: any;
50
+ };
26
51
  placeholders: Record<string, JDPlaceholderData[]>;
27
52
  }
28
53
  interface JDContext {
@@ -39,4 +64,4 @@ interface JDLayoutResponse {
39
64
  }
40
65
  declare const fetchJDLayout: (apiUrl: string, slug: string, locale?: string, options?: RequestInit) => Promise<JDLayoutResponse | null>;
41
66
 
42
- export { ComponentFactory, type ComponentFactoryProps, type JDContext, type JDLayoutResponse, type JDPlaceholderData, type JDRoute, Placeholder, type PlaceholderProps, fetchJDLayout };
67
+ export { ComponentFactory, type ComponentFactoryProps, type JDContext, JDLayout, type JDLayoutProps, type JDLayoutResponse, type JDPlaceholderData, type JDRoute, Placeholder, type PlaceholderProps, fetchJDLayout };
package/dist/index.js CHANGED
@@ -31,6 +31,7 @@ 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,
34
35
  Placeholder: () => Placeholder,
35
36
  fetchJDLayout: () => fetchJDLayout
36
37
  });
@@ -86,6 +87,20 @@ var Placeholder = ({ name, rendering, customProps, componentMap }) => {
86
87
  )));
87
88
  };
88
89
 
90
+ // src/Layout.tsx
91
+ var import_react2 = __toESM(require("react"));
92
+ var JDLayout = ({ layoutData, placeholderComponent: Placeholder2 }) => {
93
+ const { route, context } = layoutData.strapi;
94
+ 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(
95
+ Placeholder2,
96
+ {
97
+ name: "header",
98
+ rendering: route.placeholders.header || [],
99
+ customProps: { locales: context.locales, currentLocale: context.language }
100
+ }
101
+ )), /* @__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
+ };
103
+
89
104
  // src/index.ts
90
105
  var fetchJDLayout = async (apiUrl, slug, locale = "en", options) => {
91
106
  try {
@@ -106,6 +121,7 @@ var fetchJDLayout = async (apiUrl, slug, locale = "en", options) => {
106
121
  // Annotate the CommonJS export names for ESM import in node:
107
122
  0 && (module.exports = {
108
123
  ComponentFactory,
124
+ JDLayout,
109
125
  Placeholder,
110
126
  fetchJDLayout
111
127
  });
package/dist/index.mjs CHANGED
@@ -48,6 +48,20 @@ 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
+
51
65
  // src/index.ts
52
66
  var fetchJDLayout = async (apiUrl, slug, locale = "en", options) => {
53
67
  try {
@@ -67,6 +81,7 @@ var fetchJDLayout = async (apiUrl, slug, locale = "en", options) => {
67
81
  };
68
82
  export {
69
83
  ComponentFactory,
84
+ JDLayout,
70
85
  Placeholder,
71
86
  fetchJDLayout
72
87
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-layout-sdk",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
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/index.ts CHANGED
@@ -1,5 +1,7 @@
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';
3
5
 
4
6
  // Useful type definitions for the API response
5
7
  export interface JDPlaceholderData {
@@ -10,6 +12,13 @@ export interface JDPlaceholderData {
10
12
  export interface JDRoute {
11
13
  name: string;
12
14
  displayName: string;
15
+ fields?: Record<string, any>;
16
+ seo?: {
17
+ metaTitle?: string;
18
+ metaDescription?: string;
19
+ metaImage?: any;
20
+ [key: string]: any;
21
+ };
13
22
  placeholders: Record<string, JDPlaceholderData[]>;
14
23
  }
15
24