<commit_before>import { DOCS_MODE } from 'global';
import { toId, sanitize } from '@storybook/csf';

import {
  transformStoriesRawToStoriesHash,
  StoriesHash,
  Story,
  Group,
  StoriesRaw,
  StoryId,
  isStory,
} from '../lib/stories';

import { Module } from '../index';

type Direction = -1 | 1;
type ParameterName = string;

type ViewMode = 'story' | 'info' | 'settings' | string | undefined;

export interface SubState {
  storiesHash: StoriesHash;
  storyId: StoryId;
  viewMode: ViewMode;
  storiesConfigured: boolean;
}

export interface SubAPI {
  storyId: typeof toId;
  selectStory: (kindOrId: string, story?: string, obj?: any) => void;
  getCurrentStoryData: () => Story | Group;
  setStories: (stories: StoriesRaw) => void;
  jumpToComponent: (direction: Direction) => void;
  jumpToStory: (direction: Direction) => void;
  getData: (storyId: StoryId) => Story | Group;
  getParameters: (storyId: StoryId, parameterName?: ParameterName) => Story['parameters'] | any;
  getCurrentParameter<S>(parameterName?: ParameterName): S;
}

// When adding a group, also add all of its children, depth first

const initStoriesApi = ({
  store,
  navigate,
  storyId: initialStoryId,
  viewMode: initialViewMode,
}: Module) => {
  const getData = (storyId: StoryId) => {
    const { storiesHash } = store.getState();

    if (storiesHash[storyId]) {
      return storiesHash[storyId];
    }

    return undefined;<commit_msg>ADD ability to getData to get stories from refs<commit_after>import { DOCS_MODE } from 'global';
import { toId, sanitize } from '@storybook/csf';

import {
  transformStoriesRawToStoriesHash,
  StoriesHash,
  Story,
  Group,
  StoriesRaw,
  StoryId,
  isStory,
} from '../lib/stories';

import { Module } from '../index';

type Direction = -1 | 1;
type ParameterName = string;

type ViewMode = 'story' | 'info' | 'settings' | string | undefined;

export interface SubState {
  storiesHash: StoriesHash;
  storyId: StoryId;
  viewMode: ViewMode;
  storiesConfigured: boolean;
}

export interface SubAPI {
  storyId: typeof toId;
  selectStory: (kindOrId: string, story?: string, obj?: any) => void;
  getCurrentStoryData: () => Story | Group;
  setStories: (stories: StoriesRaw) => void;
  jumpToComponent: (direction: Direction) => void;
  jumpToStory: (direction: Direction) => void;
  getData: (storyId: StoryId) => Story | Group;
  getParameters: (storyId: StoryId, parameterName?: ParameterName) => Story['parameters'] | any;
  getCurrentParameter<S>(parameterName?: ParameterName): S;
}

// When adding a group, also add all of its children, depth first
const split = /((\w*)_)?(.*)/;

const initStoriesApi = ({
  store,
  navigate,
  storyId: initialStoryId,
  viewMode: initialViewMode,
}: Module) => {
  const getData = (storyId: StoryId) => {
    const { storiesHash, refs } = store.getState();

    if (storiesHash[storyId]) {
      return storiesHash[storyId];
    }

    const [, , refId, realId] = storyId.match(split);

    if (refs[refId] && refs[refId].data[storyId]) {
      return refs[refId].data[storyId];
    }

    return undefined;
{'fraction_non_alphanumeric': 0.13590658449562115, 'fraction_numerical': 0.0012974375608173856, 'mean_word_length': 4.280821917808219, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5424894', 'n_tokens_mistral': 1014, 'n_tokens_neox': 1002, 'n_words': 272}