fix: simplify live preview typing and update Angular integration for generic API#614
fix: simplify live preview typing and update Angular integration for generic API#614dipankarmaikap wants to merge 2 commits into
Conversation
…StoryData, and now ESM-only
|
|
nitpick: the branch name does not follow our naming guidelines and should be a little bit more descriptive: At least: |
|
|
||
| /** | ||
| * Base story type used internally. | ||
| */ |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
I think we can use esm-only profile instead of disabling it: https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/packages/cli/README.md#profiles
| */ | ||
| export async function onStoryblokEditorEvent< | ||
| T extends ISbComponentType<string> = ISbComponentType<string>, | ||
| T = unknown, |
There was a problem hiding this comment.
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> {
// ...
}There was a problem hiding this comment.
@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?
There was a problem hiding this comment.
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>(); |
|
Closing this in favour of #631 |
This PR removes the dependency on
ISbStoryDataand simplifies the typing ofonStoryblokEditorEvent.The live preview package now uses a generic
unknown-based story internally, and consumers define their ownStorytype.We also enforce an ESM-only build for the live preview package, since it is browser-only.
Changes
ISbStoryDatadependencyonStoryblokEditorEventfully genericISbComponentTypelocallyonStoryblokEditorEvent<Story>((story) => ...)usageUsage