Skip to content

feat: Add RichText multi-format support and component array reordering#11

Merged
d-winter merged 6 commits intomainfrom
feat/component-array-reordering-deletion
Mar 24, 2026
Merged

feat: Add RichText multi-format support and component array reordering#11
d-winter merged 6 commits intomainfrom
feat/component-array-reordering-deletion

Conversation

@d-winter
Copy link
Copy Markdown
Contributor

@d-winter d-winter commented Mar 17, 2026

Summary

Adds support for component array reordering and RichText multi-format handling to enable live preview updates without full page refresh.

Component Array Updates

  • ✅ Add reorderComponentArray() method for drag-and-drop reordering
  • ✅ Support transformedValue field for flattened component data from Studio
  • ✅ Add COMPONENT_ARRAY field type to TypeScript types
  • ✅ Preserve React-rendered HTML structure during DOM reordering
  • ✅ Extract component IDs from data-hygraph-component-chain attributes

RichText Improvements

  • ✅ Support multi-format RichText objects (html, markdown, text, ast)
  • ✅ Add isRichTextFormats() helper to detect multi-format objects
  • ✅ Use HTML format for rendering in formatComponentValue()
  • ✅ Backwards compatible with legacy string formats

Framework Integration

  • ✅ Add logging for Next.js App Router vs Pages Router detection
  • ✅ Improve refresh() fallback handling
  • ✅ Add onRefresh config option for custom refresh handlers

Testing

  • ✅ Add comprehensive tests for component array operations
  • ✅ Test reordering, deletion, addition scenarios
  • ✅ Test component chain filtering

Breaking Changes

None - all changes are backwards compatible:

  • transformedValue field is optional (falls back to newValue)
  • RichText format detection handles legacy string formats
  • New field types are additive

Enables

This enables live preview updates for:

  • Component array reordering (drag & drop)
  • RichText field edits within components
  • Component additions/deletions

Version

Bumped to v1.1.0 (minor) for new features.

Related PRs

🤖 Generated with Claude Code

Added COMPONENT_ARRAY field type to handle structural changes in modular component arrays. This enables real-time preview updates when components are reordered, added, or deleted.

Changes:
- Added COMPONENT_ARRAY field type to FieldType union
- Implemented updateComponentArrayField method in ContentUpdater
- Uses morphdom for efficient DOM diffing when available
- Preserves data attributes during array updates
- Added comprehensive test coverage (8 new tests)

Test coverage includes:
- Component reordering detection
- Component deletion detection
- Component addition detection
- Empty array handling
- Component chain filtering
- Data attribute preservation

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…andling

**Component Array Updates:**
- Add reorderComponentArray() method to handle drag-and-drop reordering
- Support transformedValue field for flattened component data from Studio
- Add COMPONENT_ARRAY field type to TypeScript types
- Preserve React-rendered HTML structure during reordering

**RichText Improvements:**
- Support multi-format RichText objects (html, markdown, text, ast)
- Add isRichTextFormats() helper to detect multi-format objects
- Use HTML format for rendering in formatComponentValue()
- Backwards compatible with legacy string formats

**Framework Integration:**
- Add logging for Next.js App Router vs Pages Router detection
- Improve refresh() fallback handling
- Add onRefresh config option for custom refresh handlers

**Testing:**
- Add comprehensive tests for component array operations
- Test reordering, deletion, addition scenarios
- Test component chain filtering

This enables live preview updates for:
- Component array reordering without full page refresh
- RichText field edits within components
- Component additions/deletions

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@d-winter d-winter changed the title feat: Add support for component array reordering and deletion feat: Add RichText multi-format support and component array reordering Mar 20, 2026
d-winter and others added 4 commits March 20, 2026 11:59
- Wrap COMPONENT_ARRAY case block in curly braces to fix no-case-declarations
- Replace 'any' types with proper TypeScript interfaces in FrameworkIntegration
- Fix tests to properly test DOM reordering (not rendering)
- Pre-populate DOM elements with data-hygraph-component-chain attributes
- Test actual reordering behavior (moving existing elements)
- Handle empty arrays correctly (clear container)
- Test deletion/addition scenarios realistically
- All tests now passing
…nents

When editing a newly created (unsaved) component in a union list, the
Studio sends a synthetic instanceId that doesn't match the real CMS IDs
in the DOM. Previously, findElements would fall back to updating ALL
matching elements, corrupting every component in the list.

Now the SDK distinguishes between:
- Elements without chain attrs (backward compat → fall back to all)
- Elements with chain attrs but no match (mismatch → skip update)

Also removes the onRefresh call for new components in
reorderComponentArray since the API doesn't have unsaved data anyway.
Bumps version from 1.1.0 to 1.0.7.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The env.d.ts file was missing from git, causing tsc --noEmit to fail
in CI while working locally (Vite injects the constant at build time).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@d-winter d-winter merged commit a4bd6cb into main Mar 24, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant