forked from RocketChat/Rocket.Chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Some Livechat modules to TypeScript (RocketChat#30366)
- Loading branch information
Showing
81 changed files
with
511 additions
and
293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { action } from '@storybook/addon-actions'; | ||
import { type DecoratorFunction } from '@storybook/csf'; | ||
import type { Args, PreactFramework } from '@storybook/preact'; | ||
import { loremIpsum as originalLoremIpsum } from 'lorem-ipsum'; | ||
|
||
import gazzoAvatar from './assets/gazzo.jpg'; | ||
import martinAvatar from './assets/martin.jpg'; | ||
import tassoAvatar from './assets/tasso.jpg'; | ||
|
||
export const screenDecorator: DecoratorFunction<PreactFramework, Args> = (storyFn) => ( | ||
<div style={{ display: 'flex', width: 365, height: 500 }}>{storyFn()}</div> | ||
); | ||
|
||
export const screenProps = () => ({ | ||
theme: { | ||
color: '', | ||
fontColor: '', | ||
iconColor: '', | ||
}, | ||
notificationsEnabled: true, | ||
minimized: false, | ||
windowed: false, | ||
onEnableNotifications: action('enableNotifications'), | ||
onDisableNotifications: action('disableNotifications'), | ||
onMinimize: action('minimize'), | ||
onRestore: action('restore'), | ||
onOpenWindow: action('openWindow'), | ||
}); | ||
|
||
export const avatarResolver = (username: string) => | ||
({ | ||
'guilherme.gazzo': gazzoAvatar, | ||
'martin.schoeler': martinAvatar, | ||
'tasso.evangelista': tassoAvatar, | ||
}[username]); | ||
|
||
export const attachmentResolver = (url: string) => url; | ||
|
||
const createRandom = (s: number) => () => { | ||
s = Math.sin(s) * 10000; | ||
return s - Math.floor(s); | ||
}; | ||
const loremIpsumRandom = createRandom(42); | ||
export const loremIpsum = (options: Parameters<typeof originalLoremIpsum>[0]) => | ||
originalLoremIpsum({ random: loremIpsumRandom, ...options }); | ||
|
||
export { gazzoAvatar, martinAvatar, tassoAvatar }; | ||
|
||
export { default as sampleAudio } from './assets/sample-audio.mp3'; | ||
export { default as sampleImage } from './assets/sample-image.jpg'; | ||
export { default as sampleVideo } from './assets/sample-video.mp4'; | ||
export { default as accessoryImage } from './assets/accessoryImage.png'; | ||
export { default as imageBlock } from './assets/imageBlock.png'; | ||
export { default as beepAudio } from './assets/beep.mp3'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
declare const path: string; | ||
|
||
export = path; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { type StorybookConfig } from '@storybook/core-common'; | ||
import { type RuleSetRule } from 'webpack'; | ||
|
||
const config: StorybookConfig = { | ||
stories: ['../src/**/{*.story,story,*.stories,stories}.{js,tsx}'], | ||
addons: [ | ||
{ | ||
name: '@storybook/addon-essentials', | ||
options: { | ||
backgrounds: false, | ||
}, | ||
}, | ||
'@storybook/addon-postcss', | ||
'storybook-dark-mode', | ||
], | ||
core: { | ||
builder: 'webpack4', | ||
}, | ||
webpackFinal: async (config) => { | ||
if (!config.resolve || !config.module) { | ||
throw new Error('Invalid webpack config'); | ||
} | ||
|
||
config.resolve.alias = { | ||
...config.resolve.alias, | ||
'react': 'preact/compat', | ||
'react-dom/test-utils': 'preact/test-utils', | ||
'react-dom': 'preact/compat', | ||
'react/jsx-runtime': 'preact/jsx-runtime', | ||
[require.resolve('../src/lib/uiKit')]: require.resolve('./mocks/uiKit.ts'), | ||
}; | ||
|
||
const isRuleSetRule = (rule: any): rule is RuleSetRule => typeof rule === 'object' && rule.test && rule.use; | ||
|
||
config.module.rules ??= []; | ||
|
||
config.module.rules = config.module.rules.filter( | ||
(rule) => isRuleSetRule(rule) && (typeof rule.loader !== 'string' || !/json-loader/.test(rule.loader)), | ||
); | ||
|
||
const fileLoader = config.module.rules.find( | ||
(rule): rule is RuleSetRule => isRuleSetRule(rule) && typeof rule.loader === 'string' && /file-loader/.test(rule.loader), | ||
); | ||
if (!fileLoader) { | ||
throw new Error('Invalid webpack config'); | ||
} | ||
fileLoader.test = /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|cur|ani|pdf|mp3|mp4)(\?.*)?$/; | ||
|
||
const urlLoader = config.module.rules | ||
?.filter(isRuleSetRule) | ||
.find(({ loader }) => typeof loader === 'string' && /url-loader/.test(loader)); | ||
if (!urlLoader) { | ||
throw new Error('Invalid webpack config'); | ||
} | ||
urlLoader.test = /\.(webm|wav|m4a|aac|oga)(\?.*)?$/; | ||
|
||
config.module.rules.push({ | ||
test: /\.scss$/, | ||
use: [ | ||
'style-loader', | ||
{ | ||
loader: 'css-loader', | ||
options: { | ||
sourceMap: true, | ||
modules: true, | ||
importLoaders: 1, | ||
}, | ||
}, | ||
'sass-loader', | ||
], | ||
}); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const path = require('path'); | ||
|
||
const logoPath = path.resolve(path.join(__dirname, './logo.svg')); | ||
|
||
config.module.rules.push({ | ||
...fileLoader, | ||
test: (srcPath) => srcPath === logoPath, | ||
}); | ||
|
||
config.module.rules.push({ | ||
test: (srcPath) => srcPath.endsWith('.svg') && srcPath !== logoPath, | ||
use: ['desvg-loader/preact', 'svg-loader'], | ||
}); | ||
|
||
return config; | ||
}, | ||
}; | ||
|
||
module.exports = config; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { type Parameters } from '@storybook/addons'; | ||
import { themes } from '@storybook/theming'; | ||
|
||
import manifest from '../package.json'; | ||
import logo from './logo.svg'; | ||
import 'emoji-mart/css/emoji-mart.css'; | ||
import '../src/styles/index.scss'; | ||
|
||
export const parameters: Parameters = { | ||
actions: { argTypesRegex: '^on[A-Z].*' }, | ||
backgrounds: { | ||
grid: { | ||
cellSize: 4, | ||
cellAmount: 4, | ||
opacity: 0.5, | ||
}, | ||
}, | ||
options: { | ||
storySort: ([, a], [, b]) => a.kind.localeCompare(b.kind), | ||
}, | ||
layout: 'fullscreen', | ||
darkMode: { | ||
dark: { | ||
...themes.dark, | ||
brandTitle: manifest.name, | ||
brandImage: logo, | ||
brandUrl: manifest.homepage, | ||
}, | ||
light: { | ||
...themes.normal, | ||
brandTitle: manifest.name, | ||
brandImage: logo, | ||
brandUrl: manifest.homepage, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { type CSSProperties } from 'preact/compat'; | ||
|
||
export type Theme = { | ||
color: CSSProperties['backgroundColor']; | ||
fontColor: CSSProperties['color']; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.