react-layout-sdk 1.1.6 → 1.1.7
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 +72 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/package.json +1 -1
- package/src/index.ts +7 -0
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
|
@@ -23,6 +23,13 @@ interface JDPlaceholderData {
|
|
|
23
23
|
interface JDRoute {
|
|
24
24
|
name: string;
|
|
25
25
|
displayName: string;
|
|
26
|
+
fields?: Record<string, any>;
|
|
27
|
+
seo?: {
|
|
28
|
+
metaTitle?: string;
|
|
29
|
+
metaDescription?: string;
|
|
30
|
+
metaImage?: any;
|
|
31
|
+
[key: string]: any;
|
|
32
|
+
};
|
|
26
33
|
placeholders: Record<string, JDPlaceholderData[]>;
|
|
27
34
|
}
|
|
28
35
|
interface JDContext {
|
package/dist/index.d.ts
CHANGED
|
@@ -23,6 +23,13 @@ interface JDPlaceholderData {
|
|
|
23
23
|
interface JDRoute {
|
|
24
24
|
name: string;
|
|
25
25
|
displayName: string;
|
|
26
|
+
fields?: Record<string, any>;
|
|
27
|
+
seo?: {
|
|
28
|
+
metaTitle?: string;
|
|
29
|
+
metaDescription?: string;
|
|
30
|
+
metaImage?: any;
|
|
31
|
+
[key: string]: any;
|
|
32
|
+
};
|
|
26
33
|
placeholders: Record<string, JDPlaceholderData[]>;
|
|
27
34
|
}
|
|
28
35
|
interface JDContext {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -10,6 +10,13 @@ export interface JDPlaceholderData {
|
|
|
10
10
|
export interface JDRoute {
|
|
11
11
|
name: string;
|
|
12
12
|
displayName: string;
|
|
13
|
+
fields?: Record<string, any>;
|
|
14
|
+
seo?: {
|
|
15
|
+
metaTitle?: string;
|
|
16
|
+
metaDescription?: string;
|
|
17
|
+
metaImage?: any;
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
};
|
|
13
20
|
placeholders: Record<string, JDPlaceholderData[]>;
|
|
14
21
|
}
|
|
15
22
|
|