<commit_before>import React from 'react'
import { storiesOf } from '@storybook/react'
import { action } from '@storybook/addon-actions'
import { withInfo } from '@storybook/addon-info'
import { withKnobs, text } from '@storybook/addon-knobs'
import {
  withLocalStyle,
  withi18nNS,
  withSideEffect,
  withSaladictPanel
} from '@/_helpers/storybook'
import { Suggest, SuggestItem } from './Suggest'
import { Message } from '@/typings/message'

storiesOf('Content Scripts|Menubar', module)
  .addParameters({
    backgrounds: [
      { name: 'MenuBar', value: '#5caf9e', default: true },
      { name: 'Black', value: '#000' }
    ]
  })
  .addDecorator(
    withInfo({
      inline: true,
      header: false
    })
  )
  .addDecorator(withKnobs)
  .addDecorator(withSaladictPanel)
  .addDecorator(withLocalStyle(require('./Suggest.scss')))
  .addDecorator(withLocalStyle(require('@/_sass_global/_reset.scss')))
  .addDecorator(withi18nNS('content'))
  .addDecorator(
    withSideEffect(() => {
      // @ts-ignore
      browser.runtime.sendMessage.callsFake((message: Message) => {
        if (message.type === 'GET_SUGGESTS') {
          return new Promise(resolve => {
            setTimeout(() => {
              resolve(fakeSuggest(message.payload))
            }, Math.random() * 1500)
          })
        }
        return Promise.resolve()
      })
    })
  )
  .add('Suggest', () => {
    return (
      <Suggest
        text={text('Search text', 'text')}
        onSelect={action('Select')}
        onFocus={action('Focus')}
        onBlur={action('Blur')}
      />
    )
  })

function fakeSuggest(text: string): SuggestItem[] {
  return Array.from(Array(10)).map((v, i) => ({
    explain: `单词 ${text} 的各种相近的建议#${i}`,
    entry: `Word ${text}#${i}`
  }))
}<commit_msg>chore(storybook): clean up browser fake<commit_after>import React from 'react'
import { storiesOf } from '@storybook/react'
import { action } from '@storybook/addon-actions'
import { withInfo } from '@storybook/addon-info'
import { withKnobs, text } from '@storybook/addon-knobs'
import {
  withLocalStyle,
  withi18nNS,
  withSideEffect,
  withSaladictPanel
} from '@/_helpers/storybook'
import { Suggest, SuggestItem } from './Suggest'
import { Message } from '@/typings/message'

storiesOf('Content Scripts|Menubar', module)
  .addParameters({
    backgrounds: [
      { name: 'MenuBar', value: '#5caf9e', default: true },
      { name: 'Black', value: '#000' }
    ]
  })
  .addDecorator(
    withInfo({
      inline: true,
      header: false
    })
  )
  .addDecorator(withKnobs)
  .addDecorator(withSaladictPanel)
  .addDecorator(withLocalStyle(require('./Suggest.scss')))
  .addDecorator(withLocalStyle(require('@/_sass_global/_reset.scss')))
  .addDecorator(withi18nNS('content'))
  .addDecorator(
    withSideEffect(() => {
      // @ts-ignore
      browser.runtime.sendMessage.callsFake((message: Message) => {
        if (message.type === 'GET_SUGGESTS') {
          return new Promise(resolve => {
            setTimeout(() => {
              resolve(fakeSuggest(message.payload))
            }, Math.random() * 1500)
          })
        }
        return Promise.resolve()
      })

      return () =>
        // @ts-ignore
        browser.runtime.sendMessage.callsFake(() => Promise.resolve())
    })
  )
  .add('Suggest', () => {
    return (
      <Suggest
        text={text('Search text', 'text')}
        onSelect={action('Select')}
        onFocus={action('Focus')}
        onBlur={action('Blur')}
      />
    )
  })

function fakeSuggest(text: string): SuggestItem[] {
  return Array.from(Array(10)).map((v, i) => ({
    explain: `单词 ${text} 的各种相近的建议#${i}`,
    entry: `Word ${text}#${i}`
  }))
}
{'fraction_non_alphanumeric': 0.16842389835090565, 'fraction_numerical': 0.008110300081103, 'mean_word_length': 2.9742212674543502, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '929434', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1252, 'n_words': 214}