Skip to content

Commit 0414239

Browse files
committed
feat: pwa pd support
1 parent 06c022d commit 0414239

File tree

37 files changed

+2460
-330
lines changed

37 files changed

+2460
-330
lines changed

packages/commerce-sdk-react/PAGE_DESIGNER.md

Lines changed: 555 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
# Page Designer Concepts
2+
3+
This document explains the key concepts behind the Page Designer integration for PWA Kit.
4+
5+
## How It Works
6+
7+
```
8+
Business Manager Page Designer
9+
↓ (creates JSON)
10+
Page Data (API)
11+
↓ (fetched by)
12+
PWA Kit App
13+
↓ (renders via)
14+
Page → Region → Component
15+
↓ (resolves from)
16+
Component Registry
17+
```
18+
19+
### Runtime vs Design Mode
20+
21+
The system operates in two modes:
22+
23+
1. **Runtime Mode** (normal browsing)
24+
- Components render directly from page data
25+
- No visual editing overhead
26+
- Optimized for performance
27+
28+
2. **Design Mode** (in Page Designer iframe)
29+
- Components are decorated for visual editing
30+
- Click-to-select, drag-and-drop enabled
31+
- Communicates with Business Manager via postMessage
32+
33+
## Component Hierarchy
34+
35+
### Page
36+
37+
The top-level container that:
38+
- Receives page data from the ShopperExperience API
39+
- Sets up SEO metadata (title, description, keywords)
40+
- Renders top-level regions
41+
42+
### Region
43+
44+
A container for components that:
45+
- Can exist at page level or nested inside layout components
46+
- Finds its components by `regionId`
47+
- Supports fallback and error elements
48+
49+
**Two modes of use:**
50+
```jsx
51+
// Page-level region
52+
<Region page={page} regionId="main" />
53+
54+
// Nested region (inside a layout component)
55+
<Region component={component} regionId="left" />
56+
```
57+
58+
### Component
59+
60+
Resolves and renders individual Page Designer components:
61+
- Looks up the React component from the registry by `typeId`
62+
- Passes component data as props
63+
- Handles lazy loading via Suspense
64+
65+
## Component Registry
66+
67+
The registry is a central place to map Page Designer type IDs to React components.
68+
69+
### Why a Registry?
70+
71+
- **Lazy Loading** - Components load only when needed
72+
- **Code Splitting** - Each component is a separate chunk
73+
- **Decoupling** - Page data doesn't need to know about React components
74+
75+
### How It Works
76+
77+
```
78+
Page Data: { typeId: "commerce_assets.banner", data: {...} }
79+
80+
Registry: "commerce_assets.banner" → () => import('./banner')
81+
82+
React Component: <Banner {...data} />
83+
```
84+
85+
## Visual Editing
86+
87+
When your app runs inside Page Designer's iframe, it enables visual editing.
88+
89+
### PageDesignerProvider
90+
91+
Wraps your app to enable design mode features:
92+
93+
```jsx
94+
<PageDesignerProvider
95+
clientId="my-storefront"
96+
targetOrigin="https://business-manager.com"
97+
mode="EDIT">
98+
{children}
99+
</PageDesignerProvider>
100+
```
101+
102+
### What It Enables
103+
104+
- **Component Selection** - Click components to select them
105+
- **Visual Indicators** - Borders and overlays show component boundaries
106+
- **Live Updates** - Changes in Page Designer reflect immediately
107+
- **Communication** - postMessage bridge to Business Manager
108+
109+
### Mode Detection
110+
111+
Detect if you're in design mode:
112+
113+
```jsx
114+
import {usePageDesignerMode} from '@salesforce/commerce-sdk-react/components'
115+
116+
function MyComponent() {
117+
const {isDesignMode, isPreviewMode} = usePageDesignerMode()
118+
// ...
119+
}
120+
```
121+
122+
Or use utility functions:
123+
124+
```jsx
125+
import {isDesignModeActive, isPreviewModeActive} from '@salesforce/commerce-sdk-react/components'
126+
```
127+
128+
## Data Flow
129+
130+
### Page Data Structure
131+
132+
```typescript
133+
Page
134+
├── id: string
135+
├── pageTitle, pageDescription, pageKeywords
136+
└── regions: Region[]
137+
└── Region
138+
├── id: string
139+
└── components: Component[]
140+
└── Component
141+
├── id: string
142+
├── typeId: string (maps to registry)
143+
├── data: {...} (your component props)
144+
└── regions?: Region[] (for layouts)
145+
```
146+
147+
### Props Your Components Receive
148+
149+
```jsx
150+
function MyComponent({
151+
// Your custom attributes from Page Designer
152+
title,
153+
image,
154+
link,
155+
156+
// Automatic props
157+
designMetadata, // { id, name, isVisible, isLocalized, isFragment }
158+
component, // Full component object
159+
regionId, // Parent region's ID
160+
regions // Child regions (for layout components)
161+
}) {
162+
// ...
163+
}
164+
```
165+
166+
## Layout Components
167+
168+
Layout components contain regions that hold other components.
169+
170+
### Example Structure
171+
172+
```
173+
TwoColumnLayout (component)
174+
├── regions.left (region)
175+
│ └── Banner (component)
176+
└── regions.right (region)
177+
└── ImageTile (component)
178+
```
179+
180+
### Implementing a Layout
181+
182+
```jsx
183+
function TwoColumnLayout({component}) {
184+
return (
185+
<div className="two-column">
186+
<Region component={component} regionId="left" />
187+
<Region component={component} regionId="right" />
188+
</div>
189+
)
190+
}
191+
```
192+
193+
## Performance
194+
195+
### Zero Overhead in Runtime
196+
197+
When not in design mode:
198+
- No design decorators applied
199+
- No postMessage listeners
200+
- Components render directly
201+
202+
### Lazy Loading
203+
204+
Components load on demand:
205+
- Initial bundle stays small
206+
- Each component is a separate chunk
207+
- Suspense handles loading states
208+
209+
### Fallbacks
210+
211+
Provide loading states for better UX:
212+
213+
```jsx
214+
registry.registerImporter(
215+
'commerce_assets.banner',
216+
() => import('./banner'),
217+
() => import('./banner-skeleton') // Optional fallback
218+
)
219+
```
220+
221+
## Related
222+
223+
- [Migration Guide](./PAGE_DESIGNER.md) - Step-by-step migration instructions
224+
- [Page Designer API](https://developer.salesforce.com/docs/commerce/commerce-api/guide/page-designer.html)

0 commit comments

Comments
 (0)