mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-07 07:21:17 +08:00
Bunch of updates I missed
This commit is contained in:
parent
668565a317
commit
b25ec312a1
@ -4,7 +4,7 @@ module.exports = {
|
||||
'<rootDir>/frameworks/!(angular)*',
|
||||
'<rootDir>/lib/*',
|
||||
'<rootDir>/renderers/*',
|
||||
'<rootDir>/ui/*',
|
||||
'<rootDir>/ui/!(node_modules)*',
|
||||
],
|
||||
collectCoverage: false,
|
||||
collectCoverageFrom: [
|
||||
|
@ -326,7 +326,9 @@ export function useStorybookApi(): API {
|
||||
}
|
||||
|
||||
export type {
|
||||
/** @deprecated now IndexHash */
|
||||
API_IndexHash as StoriesHash,
|
||||
API_IndexHash as IndexHash,
|
||||
API_RootEntry as RootEntry,
|
||||
API_GroupEntry as GroupEntry,
|
||||
API_ComponentEntry as ComponentEntry,
|
||||
|
@ -15,7 +15,7 @@ import type {
|
||||
API_RootEntry,
|
||||
API_GroupEntry,
|
||||
API_ComponentEntry,
|
||||
API_StoriesHash,
|
||||
API_IndexHash,
|
||||
API_DocsEntry,
|
||||
API_StoryEntry,
|
||||
API_HashEntry,
|
||||
@ -122,7 +122,7 @@ export const transformStoryIndexToStoriesHash = (
|
||||
provider: API_Provider<API>;
|
||||
docsOptions: DocsOptions;
|
||||
}
|
||||
): API_StoriesHash => {
|
||||
): API_IndexHash => {
|
||||
if (!index.v) throw new Error('Composition: Missing stories.json version');
|
||||
|
||||
const v4Index = index.v === 4 ? index : transformStoryIndexV3toV4(index as any);
|
||||
@ -241,10 +241,10 @@ export const transformStoryIndexToStoriesHash = (
|
||||
} as API_DocsEntry | API_StoryEntry;
|
||||
|
||||
return acc;
|
||||
}, {} as API_StoriesHash);
|
||||
}, {} as API_IndexHash);
|
||||
|
||||
// This function adds a "root" or "orphan" and all of its descendents to the hash.
|
||||
function addItem(acc: API_StoriesHash, item: API_HashEntry) {
|
||||
function addItem(acc: API_IndexHash, item: API_HashEntry) {
|
||||
// If we were already inserted as part of a group, that's great.
|
||||
if (acc[item.id]) {
|
||||
return acc;
|
||||
@ -268,7 +268,7 @@ export const transformStoryIndexToStoriesHash = (
|
||||
.reduce(addItem, orphanHash);
|
||||
};
|
||||
|
||||
export const addPreparedStories = (newHash: API_StoriesHash, oldHash?: API_StoriesHash) => {
|
||||
export const addPreparedStories = (newHash: API_IndexHash, oldHash?: API_IndexHash) => {
|
||||
if (!oldHash) return newHash;
|
||||
|
||||
return Object.fromEntries(
|
||||
@ -283,7 +283,7 @@ export const addPreparedStories = (newHash: API_StoriesHash, oldHash?: API_Stori
|
||||
);
|
||||
};
|
||||
|
||||
export const getComponentLookupList = memoize(1)((hash: API_StoriesHash) => {
|
||||
export const getComponentLookupList = memoize(1)((hash: API_IndexHash) => {
|
||||
return Object.entries(hash).reduce((acc, i) => {
|
||||
const value = i[1];
|
||||
if (value.type === 'component') {
|
||||
@ -293,6 +293,6 @@ export const getComponentLookupList = memoize(1)((hash: API_StoriesHash) => {
|
||||
}, [] as StoryId[][]);
|
||||
});
|
||||
|
||||
export const getStoriesLookupList = memoize(1)((hash: API_StoriesHash) => {
|
||||
export const getStoriesLookupList = memoize(1)((hash: API_IndexHash) => {
|
||||
return Object.keys(hash).filter((k) => ['story', 'docs'].includes(hash[k].type));
|
||||
});
|
||||
|
@ -58,7 +58,7 @@ export const panels: Addon_Collection = {
|
||||
};
|
||||
|
||||
const realSidebarProps: SidebarProps = {
|
||||
stories: mockDataset.withRoot as SidebarProps['stories'],
|
||||
index: mockDataset.withRoot as SidebarProps['index'],
|
||||
menu: [],
|
||||
refs: {},
|
||||
previewInitialized: true,
|
||||
|
@ -25,9 +25,9 @@ const simple: Record<string, RefType> = {
|
||||
title: undefined,
|
||||
id: 'storybook_internal',
|
||||
url: 'iframe.html',
|
||||
ready: true,
|
||||
previewInitialized: true,
|
||||
// @ts-expect-error (invalid input)
|
||||
stories: mockDataset.withRoot,
|
||||
index: mockDataset.withRoot,
|
||||
},
|
||||
};
|
||||
|
||||
@ -37,37 +37,37 @@ const withRefs: Record<string, RefType> = {
|
||||
id: 'basic',
|
||||
title: 'Basic ref',
|
||||
url: 'https://example.com',
|
||||
ready: true,
|
||||
previewInitialized: true,
|
||||
type: 'auto-inject',
|
||||
// @ts-expect-error (invalid input)
|
||||
stories: mockDataset.noRoot,
|
||||
index: mockDataset.noRoot,
|
||||
},
|
||||
injected: {
|
||||
id: 'injected',
|
||||
title: 'Not ready',
|
||||
url: 'https://example.com',
|
||||
ready: false,
|
||||
previewInitialized: false,
|
||||
type: 'auto-inject',
|
||||
// @ts-expect-error (invalid input)
|
||||
stories: mockDataset.noRoot,
|
||||
index: mockDataset.noRoot,
|
||||
},
|
||||
unknown: {
|
||||
id: 'unknown',
|
||||
title: 'Unknown ref',
|
||||
url: 'https://example.com',
|
||||
ready: true,
|
||||
previewInitialized: true,
|
||||
type: 'unknown',
|
||||
// @ts-expect-error (invalid input)
|
||||
stories: mockDataset.noRoot,
|
||||
index: mockDataset.noRoot,
|
||||
},
|
||||
lazy: {
|
||||
id: 'lazy',
|
||||
title: 'Lazy loaded ref',
|
||||
url: 'https://example.com',
|
||||
ready: false,
|
||||
previewInitialized: false,
|
||||
type: 'lazy',
|
||||
// @ts-expect-error (invalid input)
|
||||
stories: mockDataset.withRoot,
|
||||
index: mockDataset.withRoot,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -168,7 +168,7 @@ export const RefIndicator = React.memo(
|
||||
forwardRef<HTMLElement, RefType & { state: ReturnType<typeof getStateType> }>(
|
||||
({ state, ...ref }, forwardedRef) => {
|
||||
const api = useStorybookApi();
|
||||
const list = useMemo(() => Object.values(ref.stories || {}), [ref.stories]);
|
||||
const list = useMemo(() => Object.values(ref.index || {}), [ref.index]);
|
||||
const componentCount = useMemo(
|
||||
() => list.filter((v) => v.type === 'component').length,
|
||||
[list]
|
||||
|
@ -176,9 +176,9 @@ export const Search = React.memo<{
|
||||
);
|
||||
|
||||
const list: SearchItem[] = useMemo(() => {
|
||||
return dataset.entries.reduce((acc: SearchItem[], [refId, { stories }]) => {
|
||||
if (stories) {
|
||||
acc.push(...Object.values(stories).map((item) => searchItem(item, dataset.hash[refId])));
|
||||
return dataset.entries.reduce((acc: SearchItem[], [refId, { index }]) => {
|
||||
if (index) {
|
||||
acc.push(...Object.values(index).map((item) => searchItem(item, dataset.hash[refId])));
|
||||
}
|
||||
return acc;
|
||||
}, []);
|
||||
|
@ -37,10 +37,10 @@ const combinedDataset = (refs: Record<string, StoriesHash>): CombinedDataset =>
|
||||
// @ts-expect-error (invalid input)
|
||||
const dataset = combinedDataset({ internal: mockDataset.withRoot, composed: mockDataset.noRoot });
|
||||
|
||||
const internal = Object.values(dataset.hash.internal.stories).map((item) =>
|
||||
const internal = Object.values(dataset.hash.internal.index).map((item) =>
|
||||
searchItem(item, dataset.hash.internal)
|
||||
);
|
||||
const composed = Object.values(dataset.hash.composed.stories).map((item) =>
|
||||
const composed = Object.values(dataset.hash.composed.index).map((item) =>
|
||||
searchItem(item, dataset.hash.composed)
|
||||
);
|
||||
const stories: SearchItem[] = internal.concat(composed);
|
||||
|
@ -1,6 +1,7 @@
|
||||
import React from 'react';
|
||||
|
||||
import type { StoriesHash } from 'lib/manager-api/src';
|
||||
import type { API_IndexHash } from 'lib/types/src';
|
||||
import { Sidebar, DEFAULT_REF_ID } from './Sidebar';
|
||||
import { standardData as standardHeaderData } from './Heading.stories';
|
||||
import * as ExplorerStories from './Explorer.stories';
|
||||
@ -19,7 +20,7 @@ export default {
|
||||
};
|
||||
|
||||
const { menu } = standardHeaderData;
|
||||
const index = mockDataset.withRoot;
|
||||
const index = mockDataset.withRoot as API_IndexHash;
|
||||
const refId = DEFAULT_REF_ID;
|
||||
const storyId = 'root-1-child-a2--grandchild-a1-1';
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/* eslint-disable storybook/use-storybook-testing-library */
|
||||
// @TODO: use addon-interactions and remove the rule disable above
|
||||
import React from 'react';
|
||||
import type { ComponentEntry, StoriesHash } from '@storybook/manager-api';
|
||||
import type { ComponentEntry, IndexHash } from '@storybook/manager-api';
|
||||
import { screen } from '@testing-library/dom';
|
||||
|
||||
import { Tree } from './Tree';
|
||||
@ -56,9 +56,9 @@ const tooltipStories = Object.keys(index).reduce((acc, key) => {
|
||||
}
|
||||
if (key.startsWith('tooltip')) acc[key] = index[key];
|
||||
return acc;
|
||||
}, {} as StoriesHash);
|
||||
}, {} as IndexHash);
|
||||
|
||||
const singleStoryComponent: StoriesHash = {
|
||||
const singleStoryComponent: IndexHash = {
|
||||
// @ts-expect-error (invalid input)
|
||||
single: {
|
||||
type: 'component',
|
||||
@ -102,7 +102,7 @@ export const SingleStoryComponents = () => {
|
||||
);
|
||||
};
|
||||
|
||||
const docsOnlySinglesStoryComponent: StoriesHash = {
|
||||
const docsOnlySinglesStoryComponent: IndexHash = {
|
||||
// @ts-expect-error (invalid input)
|
||||
single: {
|
||||
type: 'component',
|
||||
@ -147,7 +147,7 @@ export const SkipToCanvasLinkFocused = {
|
||||
isBrowsing: true,
|
||||
isMain: true,
|
||||
refId,
|
||||
data: stories,
|
||||
data: index,
|
||||
highlightedRef: { current: { itemId: 'tooltip-tooltipbuildlist--default', refId } },
|
||||
setHighlightedItemId: log,
|
||||
selectedStoryId: 'tooltip-tooltipbuildlist--default',
|
||||
|
@ -1,7 +1,7 @@
|
||||
import memoize from 'memoizerific';
|
||||
import { global } from '@storybook/global';
|
||||
import type { SyntheticEvent } from 'react';
|
||||
import type { HashEntry, StoriesHash } from '@storybook/manager-api';
|
||||
import type { HashEntry, IndexHash } from '@storybook/manager-api';
|
||||
|
||||
// eslint-disable-next-line import/no-cycle
|
||||
import { DEFAULT_REF_ID } from './Sidebar';
|
||||
@ -30,11 +30,11 @@ export const getParents = memoize(1000)((id: string, dataset: Dataset): Item[] =
|
||||
const parent = getParent(id, dataset);
|
||||
return parent ? [parent, ...getParents(parent.id, dataset)] : [];
|
||||
});
|
||||
export const getAncestorIds = memoize(1000)((data: StoriesHash, id: string): string[] =>
|
||||
export const getAncestorIds = memoize(1000)((data: IndexHash, id: string): string[] =>
|
||||
getParents(id, data).map((item) => item.id)
|
||||
);
|
||||
export const getDescendantIds = memoize(1000)(
|
||||
(data: StoriesHash, id: string, skipLeafs: boolean): string[] => {
|
||||
(data: IndexHash, id: string, skipLeafs: boolean): string[] => {
|
||||
const entry = data[id];
|
||||
const children = entry.type === 'story' || entry.type === 'docs' ? [] : entry.children;
|
||||
return children.reduce((acc, childId) => {
|
||||
@ -47,7 +47,7 @@ export const getDescendantIds = memoize(1000)(
|
||||
);
|
||||
|
||||
export function getPath(item: Item, ref: RefType): string[] {
|
||||
const parent = item.type !== 'root' && item.parent ? ref.stories[item.parent] : null;
|
||||
const parent = item.type !== 'root' && item.parent ? ref.index[item.parent] : null;
|
||||
if (parent) return [...getPath(parent, ref), parent.name];
|
||||
return ref.id === DEFAULT_REF_ID ? [] : [ref.title || ref.id];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user