Various fixes

This commit is contained in:
Tom Coleman 2022-03-07 14:53:54 +11:00
parent d270296696
commit 8d17bb8ada
3 changed files with 9 additions and 37 deletions

View File

@ -1,21 +1,15 @@
import global from 'global';
import {
AnyFramework,
StoryId,
ViewMode,
StoryContextForLoaders,
StoryContext,
} from '@storybook/csf';
import { AnyFramework, StoryId, ViewMode, StoryContextForLoaders } from '@storybook/csf';
import { Story, StoryStore, CSFFile } from '@storybook/store';
import { Channel } from '@storybook/addons';
import { DOCS_RENDERED } from '@storybook/core-events';
import { DocsContextProps } from './types';
export class DocsRender<CanvasElement extends HTMLElement | void, TFramework extends AnyFramework> {
export class DocsRender<TFramework extends AnyFramework> {
public story?: Story<TFramework>;
private canvasElement?: CanvasElement;
private canvasElement?: HTMLElement;
private context?: DocsContextProps;
@ -35,7 +29,7 @@ export class DocsRender<CanvasElement extends HTMLElement | void, TFramework ext
}
async renderToElement(
canvasElement: CanvasElement,
canvasElement: HTMLElement,
renderStoryToElement: DocsContextProps['renderStoryToElement']
) {
this.canvasElement = canvasElement;

View File

@ -5,22 +5,11 @@ import { SynchronousPromise } from 'synchronous-promise';
import Events, { IGNORED_EXCEPTION } from '@storybook/core-events';
import { logger } from '@storybook/client-logger';
import { addons, Channel } from '@storybook/addons';
import {
AnyFramework,
StoryId,
ProjectAnnotations,
Args,
Globals,
ViewMode,
StoryContextForLoaders,
StoryContext,
} from '@storybook/csf';
import { AnyFramework, StoryId, ProjectAnnotations, Args, Globals } from '@storybook/csf';
import {
ModuleImportFn,
Selection,
Story,
RenderContext,
CSFFile,
StoryStore,
StorySpecifier,
StoryIndex,
@ -33,24 +22,13 @@ import { WebView } from './WebView';
import { StoryRender } from './StoryRender';
import { DocsRender } from './DocsRender';
const { window: globalWindow, AbortController, fetch } = global;
const { window: globalWindow, fetch } = global;
function focusInInput(event: Event) {
const target = event.target as Element;
return /input|textarea/i.test(target.tagName) || target.getAttribute('contenteditable') !== null;
}
function createController(): AbortController {
if (AbortController) return new AbortController();
// Polyfill for IE11
return {
signal: { aborted: false },
abort() {
this.signal.aborted = true;
},
} as AbortController;
}
type PromiseLike<T> = Promise<T> | SynchronousPromise<T>;
type MaybePromise<T> = Promise<T> | T;
type StoryCleanupFn = () => MaybePromise<void>;
@ -58,7 +36,7 @@ type StoryCleanupFn = () => MaybePromise<void>;
const STORY_INDEX_PATH = './stories.json';
type HTMLStoryRender<TFramework extends AnyFramework> = StoryRender<HTMLElement, TFramework>;
type HTMLDocsRender<TFramework extends AnyFramework> = DocsRender<HTMLElement, TFramework>;
type HTMLDocsRender<TFramework extends AnyFramework> = DocsRender<TFramework>;
export class PreviewWeb<TFramework extends AnyFramework> {
channel: Channel;

View File

@ -100,7 +100,7 @@ export class StoryRender<
}
// The two story "renders" are equal and have both loaded the same story
isEqual(other?: StoryRender<CanvasElement, TFramework> | DocsRender<CanvasElement, TFramework>) {
isEqual(other?: StoryRender<CanvasElement, TFramework> | DocsRender<TFramework>) {
return other && this.id === other.id && this.story && this.story === other.story;
}
@ -109,7 +109,7 @@ export class StoryRender<
}
toDocsRender() {
return new DocsRender<CanvasElement, TFramework>(this.channel, this.store, this.id, this.story);
return new DocsRender<TFramework>(this.channel, this.store, this.id, this.story);
}
context() {