2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2019 Signal Messenger, LLC
|
2022-06-07 00:48:02 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2023-10-11 19:06:43 +00:00
|
|
|
import '../ts/window.d.ts';
|
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
import React from 'react';
|
2023-10-11 19:06:43 +00:00
|
|
|
|
|
|
|
import 'sanitize.css';
|
|
|
|
import '../stylesheets/manifest.scss';
|
2022-06-07 00:48:02 +00:00
|
|
|
|
|
|
|
import * as styles from './styles.scss';
|
|
|
|
import messages from '../_locales/en/messages.json';
|
|
|
|
import { StorybookThemeContext } from './StorybookThemeContext';
|
|
|
|
import { ThemeType } from '../ts/types/Util';
|
2023-03-01 19:00:50 +00:00
|
|
|
import { setupI18n } from '../ts/util/setupI18n';
|
2023-07-31 16:23:19 +00:00
|
|
|
import { HourCyclePreference } from '../ts/types/I18N';
|
2023-10-11 19:06:43 +00:00
|
|
|
import { Provider } from 'react-redux';
|
|
|
|
import { Store, combineReducers, createStore } from 'redux';
|
|
|
|
import { StateType } from '../ts/state/reducer';
|
|
|
|
import {
|
|
|
|
ScrollerLockContext,
|
|
|
|
createScrollerLock,
|
|
|
|
} from '../ts/hooks/useScrollLock';
|
2024-04-16 20:13:02 +00:00
|
|
|
import { Environment, setEnvironment } from '../ts/environment.ts';
|
|
|
|
|
|
|
|
setEnvironment(Environment.Development, true);
|
2023-10-11 19:06:43 +00:00
|
|
|
|
|
|
|
const i18n = setupI18n('en', messages);
|
2022-06-07 00:48:02 +00:00
|
|
|
|
|
|
|
export const globalTypes = {
|
|
|
|
mode: {
|
|
|
|
name: 'Mode',
|
|
|
|
description: 'Application mode',
|
|
|
|
defaultValue: 'mouse',
|
|
|
|
toolbar: {
|
|
|
|
dynamicTitle: true,
|
|
|
|
icon: 'circlehollow',
|
|
|
|
items: ['mouse', 'keyboard'],
|
|
|
|
showName: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
theme: {
|
|
|
|
name: 'Theme',
|
|
|
|
description: 'Global theme for components',
|
|
|
|
defaultValue: 'light',
|
|
|
|
toolbar: {
|
|
|
|
dynamicTitle: true,
|
|
|
|
icon: 'circlehollow',
|
|
|
|
items: ['light', 'dark'],
|
|
|
|
showName: true,
|
|
|
|
},
|
|
|
|
},
|
2024-01-19 22:00:13 +00:00
|
|
|
direction: {
|
|
|
|
name: 'Direction',
|
|
|
|
description: 'Direction of text',
|
|
|
|
defaultValue: 'auto',
|
|
|
|
toolbar: {
|
|
|
|
dynamicTitle: true,
|
|
|
|
icon: 'circlehollow',
|
|
|
|
items: ['auto', 'ltr', 'rtl'],
|
|
|
|
showName: true,
|
|
|
|
},
|
|
|
|
},
|
2022-06-07 00:48:02 +00:00
|
|
|
};
|
|
|
|
|
2023-10-11 19:06:43 +00:00
|
|
|
const mockStore: Store<StateType> = createStore(
|
|
|
|
combineReducers({
|
|
|
|
calling: (state = {}) => state,
|
|
|
|
conversations: (
|
|
|
|
state = {
|
|
|
|
conversationLookup: {},
|
|
|
|
targetedConversationPanels: {},
|
|
|
|
}
|
|
|
|
) => state,
|
|
|
|
globalModals: (state = {}) => state,
|
|
|
|
user: (state = {}) => state,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
// eslint-disable-next-line
|
|
|
|
const noop = () => {};
|
|
|
|
|
|
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
window.Whisper.events = {
|
|
|
|
on: noop,
|
2024-03-18 21:48:00 +00:00
|
|
|
off: noop,
|
2023-10-11 19:06:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
window.SignalContext = {
|
|
|
|
i18n,
|
|
|
|
|
|
|
|
activeWindowService: {
|
|
|
|
isActive: () => true,
|
|
|
|
registerForActive: noop,
|
|
|
|
unregisterForActive: noop,
|
|
|
|
registerForChange: noop,
|
|
|
|
unregisterForChange: noop,
|
|
|
|
},
|
|
|
|
|
|
|
|
nativeThemeListener: {
|
|
|
|
getSystemTheme: () => 'light',
|
|
|
|
subscribe: noop,
|
|
|
|
unsubscribe: noop,
|
|
|
|
update: () => 'light',
|
|
|
|
},
|
|
|
|
Settings: {
|
|
|
|
themeSetting: {
|
|
|
|
getValue: async () => 'light',
|
|
|
|
setValue: async () => 'light',
|
|
|
|
},
|
|
|
|
waitForChange: () => new Promise(noop),
|
|
|
|
},
|
|
|
|
OS: {
|
|
|
|
getClassName: () => '',
|
|
|
|
platform: '',
|
|
|
|
release: '',
|
|
|
|
},
|
|
|
|
config: {} as any,
|
|
|
|
|
|
|
|
getHourCyclePreference: () => HourCyclePreference.UnknownPreference,
|
|
|
|
getPreferredSystemLocales: () => ['en'],
|
2023-11-07 01:02:13 +00:00
|
|
|
getLocaleOverride: () => null,
|
2023-11-08 20:39:56 +00:00
|
|
|
getLocaleDisplayNames: () => ({ en: { en: 'English' } }),
|
2023-10-11 19:06:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
window.i18n = i18n;
|
|
|
|
window.ConversationController = window.ConversationController || {};
|
|
|
|
window.ConversationController.isSignalConversationId = () => false;
|
|
|
|
window.ConversationController.onConvoMessageMount = noop;
|
|
|
|
window.reduxStore = mockStore;
|
2023-03-01 19:00:50 +00:00
|
|
|
|
2024-01-19 22:00:13 +00:00
|
|
|
const withGlobalTypesProvider = (Story, context) => {
|
2022-06-07 00:48:02 +00:00
|
|
|
const theme =
|
|
|
|
context.globals.theme === 'light' ? ThemeType.light : ThemeType.dark;
|
|
|
|
const mode = context.globals.mode;
|
2024-01-19 22:00:13 +00:00
|
|
|
const direction = context.globals.direction ?? 'auto';
|
2022-06-07 00:48:02 +00:00
|
|
|
|
2024-03-12 16:29:31 +00:00
|
|
|
window.SignalContext.getResolvedMessagesLocaleDirection = () =>
|
|
|
|
direction === 'auto' ? 'ltr' : direction;
|
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
// Adding it to the body as well so that we can cover modals and other
|
|
|
|
// components that are rendered outside of this decorator container
|
|
|
|
if (theme === 'light') {
|
2023-03-28 20:31:24 +00:00
|
|
|
document.body.classList.add('light-theme');
|
2022-06-07 00:48:02 +00:00
|
|
|
document.body.classList.remove('dark-theme');
|
|
|
|
} else {
|
2023-03-28 20:31:24 +00:00
|
|
|
document.body.classList.remove('light-theme');
|
2022-06-07 00:48:02 +00:00
|
|
|
document.body.classList.add('dark-theme');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode === 'mouse') {
|
|
|
|
document.body.classList.remove('keyboard-mode');
|
|
|
|
document.body.classList.add('mouse-mode');
|
|
|
|
} else {
|
|
|
|
document.body.classList.remove('mouse-mode');
|
|
|
|
document.body.classList.add('keyboard-mode');
|
|
|
|
}
|
|
|
|
|
|
|
|
document.body.classList.add('page-is-visible');
|
|
|
|
|
2024-01-20 01:18:40 +00:00
|
|
|
document.documentElement.setAttribute('dir', direction);
|
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
return (
|
2024-01-20 01:18:40 +00:00
|
|
|
<div className={styles.container}>
|
2022-06-07 00:48:02 +00:00
|
|
|
<StorybookThemeContext.Provider value={theme}>
|
|
|
|
<Story {...context} />
|
|
|
|
</StorybookThemeContext.Provider>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-10-11 19:06:43 +00:00
|
|
|
function withMockStoreProvider(Story, context) {
|
|
|
|
return (
|
|
|
|
<Provider store={mockStore}>
|
|
|
|
<Story {...context} />
|
|
|
|
</Provider>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function withScrollLockProvider(Story, context) {
|
|
|
|
return (
|
|
|
|
<ScrollerLockContext.Provider
|
|
|
|
value={createScrollerLock('MockStories', () => {})}
|
|
|
|
>
|
|
|
|
<Story {...context} />
|
|
|
|
</ScrollerLockContext.Provider>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export const decorators = [
|
2024-01-19 22:00:13 +00:00
|
|
|
withGlobalTypesProvider,
|
2023-10-11 19:06:43 +00:00
|
|
|
withMockStoreProvider,
|
|
|
|
withScrollLockProvider,
|
|
|
|
];
|
2022-06-07 00:48:02 +00:00
|
|
|
|
|
|
|
export const parameters = {
|
|
|
|
axe: {
|
|
|
|
disabledRules: ['html-has-lang'],
|
|
|
|
},
|
|
|
|
};
|
2024-07-08 18:23:27 +00:00
|
|
|
export const tags = [];
|