import type { Meta } from "@storybook/vue3"; import type { DefineComponent } from "vue"; import { within } from "@storybook/test"; import type { ComponentPropsAndSlots, StoryObj, VueRenderer } from "@storybook/vue3"; import type { BoundFunctions, queries } from "@testing-library/vue"; import type { FunctionalComponent } from "vue"; import type { PlayFunctionContext } from "@storybook/types"; import type { Constructor } from "type-fest"; export type SlottedMeta< TComponent extends abstract new (...args: any) => any, TSlots extends string, > = Meta["$props"] & Record>>; type ComponentPropsOrProps = TCmpOrArgs extends Constructor ? ComponentPropsAndSlots : TCmpOrArgs extends FunctionalComponent ? ComponentPropsAndSlots : TCmpOrArgs; export function defineStory( config: Omit, "play"> & { play?: ( context: PlayFunctionContext> & { screen: BoundFunctions; }, ) => Promise; }, extension?: { from: StoryObj }, ): StoryObj { if (!config.play) { return config as StoryObj; } return { ...extension?.from, ...config, play: async (context: PlayFunctionContext>) => { if (!config.play) return () => void 0; const screen = within(document.body); await config.play({ ...context, screen }); }, } as unknown as StoryObj; }