Skip to content

fix: simplify live preview typing and update Angular integration for generic API#614

Closed
dipankarmaikap wants to merge 2 commits into
mainfrom
fixture/live-preview
Closed

fix: simplify live preview typing and update Angular integration for generic API#614
dipankarmaikap wants to merge 2 commits into
mainfrom
fixture/live-preview

Conversation

@dipankarmaikap

Copy link
Copy Markdown
Contributor

This PR removes the dependency on ISbStoryData and simplifies the typing of onStoryblokEditorEvent.

The live preview package now uses a generic unknown-based story internally, and consumers define their own Story type.

We also enforce an ESM-only build for the live preview package, since it is browser-only.

Changes

  • Removed ISbStoryData dependency
  • Made onStoryblokEditorEvent fully generic
  • Angular SDK now defines ISbComponentType locally
  • Adapted onStoryblokEditorEvent<Story>((story) => ...) usage
  • Live preview package is now ESM-only (browser usage only)

Usage

onStoryblokEditorEvent<Story>((story) => {
  console.log(story);
});

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Cross-package changes detected

This PR is titled as a fix commit but modifies files across 2 packages:

  • packages/angular/
  • packages/live-preview/

When this PR is squash-merged, all changes become a single fix commit.
Nx release uses file changes (not the commit scope) to determine which packages to bump,
so every package listed above will get a version bump on the next release.

If the changes to other packages are cosmetic (README fixes, dependency bumps, config cleanup),
please split them into a separate PR with a chore: title. chore commits don't trigger version bumps.

@dipankarmaikap dipankarmaikap marked this pull request as ready for review May 20, 2026 08:13
@maoberlehner

Copy link
Copy Markdown
Contributor

nitpick: the branch name does not follow our naming guidelines and should be a little bit more descriptive: At least: fix/live-preview-types


/**
* Base story type used internally.
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand why this comment is where it is. Seems unrelated to the code/comment following it.

sourcemap: true,
dts: true,
attw: true,
attw: false,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*/
export async function onStoryblokEditorEvent<
T extends ISbComponentType<string> = ISbComponentType<string>,
T = unknown,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we make this a generic? We know (can look up) what to expect from editor events.

The storyblok-bridge repo is not very specific, unfortunately.

But a somewhat honest type would be:

export type LivePreviewStory<TContent = Record<string, unknown>> = {
  id: number;
  uuid?: string;
  content?: TContent;
  [key: string]: unknown;
};

export async function onStoryblokEditorEvent<
  TContent = Record<string, unknown>,
>(
  callback: (story: LivePreviewStory<TContent>) => void,
  bridgeOptions?: BridgeParams,
): Promise<() => void> {
  // ...
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maoberlehner With this, we would still have the type mismatch issue, for example when using the Story type from the api-client.

Also, with your PR #625, do you think we should continue with this approach?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the shape of what is returned here is fundamentally incompatible with the Story coming from the CAPI. I need to change this in my PR, where I did it wrong. Go ahead with your approach here.

* Each listener receives the updated story data from the Visual Editor.
*/
const inputListeners = new Set<(story: ISbStoryData) => void>();
const inputListeners = new Set<(story: unknown) => void>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See type below

@dipankarmaikap

Copy link
Copy Markdown
Contributor Author

Closing this in favour of #631

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.

2 participants