@nuasite/cms 0.8.2 → 0.9.0

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 CHANGED
@@ -222,6 +222,82 @@ Components in `componentDirs` (default: `src/components/`) are scanned for props
222
222
 
223
223
  Both operations find the invocation site (the page file, not the component file itself), locate the correct JSX tag using occurrence indexing, and modify the source with proper indentation.
224
224
 
225
+ ## PostMessage API (Iframe Communication)
226
+
227
+ When the editor runs inside an iframe, it sends `postMessage` events to the parent window. Listen for them with:
228
+
229
+ ```typescript
230
+ window.addEventListener('message', (event) => {
231
+ const msg = event.data // CmsPostMessage
232
+ switch (msg.type) {
233
+ case 'cms-ready': /* ... */ break
234
+ case 'cms-state-changed': /* ... */ break
235
+ case 'cms-page-navigated': /* ... */ break
236
+ case 'cms-element-selected': /* ... */ break
237
+ case 'cms-element-deselected': /* ... */ break
238
+ }
239
+ })
240
+ ```
241
+
242
+ All message types are exported as TypeScript interfaces:
243
+
244
+ ```typescript
245
+ import type { CmsPostMessage, CmsReadyMessage, CmsStateChangedMessage } from '@nuasite/cms'
246
+ ```
247
+
248
+ ### `cms-ready`
249
+
250
+ Sent once when the manifest loads for the first time. Contains the full page context:
251
+
252
+ | Field | Type | Description |
253
+ |-------|------|-------------|
254
+ | `data.pathname` | `string` | Current page URL pathname |
255
+ | `data.pageTitle` | `string?` | Page title from SEO data or pages array |
256
+ | `data.seo` | `PageSeoData?` | Full SEO metadata (title, description, OG, etc.) |
257
+ | `data.pages` | `PageEntry[]?` | All site pages with pathname and title |
258
+ | `data.collectionDefinitions` | `Record<string, CollectionDefinition>?` | Content collections with inferred schemas |
259
+ | `data.componentDefinitions` | `Record<string, ComponentDefinition>?` | Registered component definitions |
260
+ | `data.availableColors` | `AvailableColors?` | Tailwind color palette |
261
+ | `data.availableTextStyles` | `AvailableTextStyles?` | Tailwind text style options |
262
+ | `data.metadata` | `ManifestMetadata?` | Manifest version, build ID, content hash |
263
+
264
+ ### `cms-state-changed`
265
+
266
+ Sent whenever editor state changes (editing mode, dirty counts, deployment, undo/redo):
267
+
268
+ | Field | Type | Description |
269
+ |-------|------|-------------|
270
+ | `state.isEditing` | `boolean` | Whether edit mode is active |
271
+ | `state.hasChanges` | `boolean` | Whether any unsaved changes exist |
272
+ | `state.dirtyCount.text` | `number` | Pending text changes |
273
+ | `state.dirtyCount.image` | `number` | Pending image changes |
274
+ | `state.dirtyCount.color` | `number` | Pending color changes |
275
+ | `state.dirtyCount.bgImage` | `number` | Pending background image changes |
276
+ | `state.dirtyCount.attribute` | `number` | Pending attribute changes |
277
+ | `state.dirtyCount.seo` | `number` | Pending SEO changes |
278
+ | `state.dirtyCount.total` | `number` | Total pending changes |
279
+ | `state.deployment.status` | `DeploymentStatusType \| null` | Current deployment status |
280
+ | `state.deployment.lastDeployedAt` | `string \| null` | ISO timestamp of last deployment |
281
+ | `state.canUndo` | `boolean` | Whether undo is available |
282
+ | `state.canRedo` | `boolean` | Whether redo is available |
283
+
284
+ ### `cms-page-navigated`
285
+
286
+ Sent when the manifest reloads after navigating to a different page:
287
+
288
+ | Field | Type | Description |
289
+ |-------|------|-------------|
290
+ | `page.pathname` | `string` | New page pathname |
291
+ | `page.title` | `string?` | Page title |
292
+
293
+ ### `cms-element-selected`
294
+
295
+ Sent when the user hovers or clicks a CMS element. Contains full element metadata from the manifest including `sourcePath`, `sourceLine`, `sourceSnippet`, `sourceHash`, `stableId`, `contentPath`, image/color/attribute data, and component instance info.
296
+
297
+ ### `cms-element-deselected`
298
+
299
+ Sent when no element is hovered. No additional data.
300
+
225
301
  ## Exports
226
302
 
227
303
  ```typescript