@cloud-ru/uikit-product-utils 7.0.0 → 7.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/cjs/components/ConfigProvider/ConfigProvider.d.ts +13 -0
  3. package/dist/cjs/components/ConfigProvider/ConfigProvider.js +13 -0
  4. package/dist/cjs/components/ConfigProvider/index.d.ts +1 -0
  5. package/dist/cjs/components/ConfigProvider/index.js +17 -0
  6. package/dist/cjs/components/ForThemeMode/ForThemeMode.d.ts +6 -0
  7. package/dist/cjs/components/ForThemeMode/ForThemeMode.js +9 -0
  8. package/dist/cjs/components/ForThemeMode/hooks.d.ts +6 -0
  9. package/dist/cjs/components/ForThemeMode/hooks.js +13 -0
  10. package/dist/cjs/components/ForThemeMode/index.d.ts +2 -0
  11. package/dist/cjs/components/ForThemeMode/index.js +18 -0
  12. package/dist/cjs/components/index.d.ts +2 -0
  13. package/dist/cjs/components/index.js +18 -0
  14. package/dist/cjs/constants/adaptive.d.ts +34 -0
  15. package/dist/cjs/constants/adaptive.js +44 -0
  16. package/dist/cjs/constants/displayMode.d.ts +16 -0
  17. package/dist/cjs/constants/displayMode.js +24 -0
  18. package/dist/cjs/constants/environment.d.ts +14 -0
  19. package/dist/cjs/constants/environment.js +18 -0
  20. package/dist/cjs/helpers/tryParseJson.d.ts +1 -0
  21. package/dist/cjs/helpers/tryParseJson.js +15 -0
  22. package/dist/cjs/hooks/index.d.ts +13 -0
  23. package/dist/cjs/hooks/index.js +29 -0
  24. package/dist/cjs/hooks/private/getCustomStore.d.ts +2 -0
  25. package/dist/cjs/hooks/private/getCustomStore.js +11 -0
  26. package/dist/cjs/hooks/useAdaptive.d.ts +4 -0
  27. package/dist/cjs/hooks/useAdaptive.js +9 -0
  28. package/dist/cjs/hooks/useBrand.d.ts +5 -0
  29. package/dist/cjs/hooks/useBrand.js +28 -0
  30. package/dist/cjs/hooks/useComponentSize.d.ts +5 -0
  31. package/dist/cjs/hooks/useComponentSize.js +36 -0
  32. package/dist/cjs/hooks/useConfig.d.ts +8 -0
  33. package/dist/cjs/hooks/useConfig.js +126 -0
  34. package/dist/cjs/hooks/useDisplayMode.d.ts +3 -0
  35. package/dist/cjs/hooks/useDisplayMode.js +9 -0
  36. package/dist/cjs/hooks/useEventHandler.d.ts +1 -0
  37. package/dist/cjs/hooks/useEventHandler.js +17 -0
  38. package/dist/cjs/hooks/useForceUpdate.d.ts +1 -0
  39. package/dist/cjs/hooks/useForceUpdate.js +8 -0
  40. package/dist/cjs/hooks/useForceUpdateOnPageLoadedCompletely.d.ts +1 -0
  41. package/dist/cjs/hooks/useForceUpdateOnPageLoadedCompletely.js +14 -0
  42. package/dist/cjs/hooks/useLanguage.d.ts +9 -0
  43. package/dist/cjs/hooks/useLanguage.js +52 -0
  44. package/dist/cjs/hooks/useMatchMedia.d.ts +7 -0
  45. package/dist/cjs/hooks/useMatchMedia.js +39 -0
  46. package/dist/cjs/hooks/useTextProvider.d.ts +4 -0
  47. package/dist/cjs/hooks/useTextProvider.js +10 -0
  48. package/dist/cjs/hooks/useTheme.d.ts +5 -0
  49. package/dist/cjs/hooks/useTheme.js +28 -0
  50. package/dist/cjs/hooks/useUniqueId.d.ts +1 -0
  51. package/dist/cjs/hooks/useUniqueId.js +8 -0
  52. package/dist/cjs/index.d.ts +7 -0
  53. package/dist/cjs/index.js +23 -0
  54. package/dist/cjs/styles/default.d.ts +9 -0
  55. package/dist/cjs/styles/default.js +65 -0
  56. package/dist/cjs/styles/index.d.ts +1 -0
  57. package/dist/cjs/styles/index.js +17 -0
  58. package/dist/cjs/types/adaptive.d.ts +7 -0
  59. package/dist/cjs/types/adaptive.js +2 -0
  60. package/dist/cjs/types/general.d.ts +9 -0
  61. package/dist/cjs/types/general.js +2 -0
  62. package/dist/cjs/types/index.d.ts +5 -0
  63. package/dist/cjs/types/index.js +21 -0
  64. package/dist/cjs/types/language.d.ts +227 -0
  65. package/dist/cjs/types/language.js +231 -0
  66. package/dist/cjs/types/theme.d.ts +18 -0
  67. package/dist/cjs/types/theme.js +23 -0
  68. package/dist/cjs/types/withSupportProps.d.ts +4 -0
  69. package/dist/cjs/types/withSupportProps.js +2 -0
  70. package/dist/cjs/utils/alert.d.ts +2 -0
  71. package/dist/cjs/utils/alert.js +7 -0
  72. package/dist/cjs/utils/createTextProvider.d.ts +2 -0
  73. package/dist/cjs/utils/createTextProvider.js +16 -0
  74. package/dist/cjs/utils/excludeSupportProps.d.ts +3 -0
  75. package/dist/cjs/utils/excludeSupportProps.js +8 -0
  76. package/dist/cjs/utils/extractSupportProps.d.ts +1 -0
  77. package/dist/cjs/utils/extractSupportProps.js +8 -0
  78. package/dist/cjs/utils/getAdaptive.d.ts +5 -0
  79. package/dist/cjs/utils/getAdaptive.js +20 -0
  80. package/dist/cjs/utils/getDisplayMode.d.ts +3 -0
  81. package/dist/cjs/utils/getDisplayMode.js +28 -0
  82. package/dist/cjs/utils/getMatchMedia.d.ts +10 -0
  83. package/dist/cjs/utils/getMatchMedia.js +21 -0
  84. package/dist/cjs/utils/getUserAgentInfo.d.ts +20 -0
  85. package/dist/cjs/utils/getUserAgentInfo.js +29 -0
  86. package/dist/cjs/utils/index.d.ts +10 -0
  87. package/dist/cjs/utils/index.js +26 -0
  88. package/dist/cjs/utils/keyboardSelectHandler.d.ts +2 -0
  89. package/dist/cjs/utils/keyboardSelectHandler.js +10 -0
  90. package/dist/cjs/utils/private/constants.d.ts +1 -0
  91. package/dist/cjs/utils/private/constants.js +4 -0
  92. package/dist/cjs/utils/private/excludeProps.d.ts +3 -0
  93. package/dist/cjs/utils/private/excludeProps.js +8 -0
  94. package/dist/cjs/utils/private/extractProps.d.ts +1 -0
  95. package/dist/cjs/utils/private/extractProps.js +10 -0
  96. package/dist/cjs/utils/uniqueId.d.ts +8 -0
  97. package/dist/cjs/utils/uniqueId.js +13 -0
  98. package/dist/esm/components/ConfigProvider/ConfigProvider.d.ts +13 -0
  99. package/dist/esm/components/ConfigProvider/ConfigProvider.js +10 -0
  100. package/dist/esm/components/ConfigProvider/index.d.ts +1 -0
  101. package/dist/esm/components/ConfigProvider/index.js +1 -0
  102. package/dist/esm/components/ForThemeMode/ForThemeMode.d.ts +6 -0
  103. package/dist/esm/components/ForThemeMode/ForThemeMode.js +6 -0
  104. package/dist/esm/components/ForThemeMode/hooks.d.ts +6 -0
  105. package/dist/esm/components/ForThemeMode/hooks.js +10 -0
  106. package/dist/esm/components/ForThemeMode/index.d.ts +2 -0
  107. package/dist/esm/components/ForThemeMode/index.js +2 -0
  108. package/dist/esm/components/index.d.ts +2 -0
  109. package/dist/esm/components/index.js +2 -0
  110. package/dist/esm/constants/adaptive.d.ts +34 -0
  111. package/dist/esm/constants/adaptive.js +41 -0
  112. package/dist/esm/constants/displayMode.d.ts +16 -0
  113. package/dist/esm/constants/displayMode.js +21 -0
  114. package/dist/esm/constants/environment.d.ts +14 -0
  115. package/dist/esm/constants/environment.js +15 -0
  116. package/dist/esm/helpers/tryParseJson.d.ts +1 -0
  117. package/dist/esm/helpers/tryParseJson.js +12 -0
  118. package/dist/esm/hooks/index.d.ts +13 -0
  119. package/dist/esm/hooks/index.js +13 -0
  120. package/dist/esm/hooks/private/getCustomStore.d.ts +2 -0
  121. package/dist/esm/hooks/private/getCustomStore.js +8 -0
  122. package/dist/esm/hooks/useAdaptive.d.ts +4 -0
  123. package/dist/esm/hooks/useAdaptive.js +6 -0
  124. package/dist/esm/hooks/useBrand.d.ts +5 -0
  125. package/dist/esm/hooks/useBrand.js +24 -0
  126. package/dist/esm/hooks/useComponentSize.d.ts +5 -0
  127. package/dist/esm/hooks/useComponentSize.js +33 -0
  128. package/dist/esm/hooks/useConfig.d.ts +8 -0
  129. package/dist/esm/hooks/useConfig.js +120 -0
  130. package/dist/esm/hooks/useDisplayMode.d.ts +3 -0
  131. package/dist/esm/hooks/useDisplayMode.js +6 -0
  132. package/dist/esm/hooks/useEventHandler.d.ts +1 -0
  133. package/dist/esm/hooks/useEventHandler.js +14 -0
  134. package/dist/esm/hooks/useForceUpdate.d.ts +1 -0
  135. package/dist/esm/hooks/useForceUpdate.js +5 -0
  136. package/dist/esm/hooks/useForceUpdateOnPageLoadedCompletely.d.ts +1 -0
  137. package/dist/esm/hooks/useForceUpdateOnPageLoadedCompletely.js +11 -0
  138. package/dist/esm/hooks/useLanguage.d.ts +9 -0
  139. package/dist/esm/hooks/useLanguage.js +48 -0
  140. package/dist/esm/hooks/useMatchMedia.d.ts +7 -0
  141. package/dist/esm/hooks/useMatchMedia.js +33 -0
  142. package/dist/esm/hooks/useTextProvider.d.ts +4 -0
  143. package/dist/esm/hooks/useTextProvider.js +6 -0
  144. package/dist/esm/hooks/useTheme.d.ts +5 -0
  145. package/dist/esm/hooks/useTheme.js +24 -0
  146. package/dist/esm/hooks/useUniqueId.d.ts +1 -0
  147. package/dist/esm/hooks/useUniqueId.js +5 -0
  148. package/dist/esm/index.d.ts +7 -0
  149. package/dist/esm/index.js +7 -0
  150. package/dist/esm/styles/default.d.ts +9 -0
  151. package/dist/esm/styles/default.js +62 -0
  152. package/dist/esm/styles/index.d.ts +1 -0
  153. package/dist/esm/styles/index.js +1 -0
  154. package/dist/esm/types/adaptive.d.ts +7 -0
  155. package/dist/esm/types/adaptive.js +1 -0
  156. package/dist/esm/types/general.d.ts +9 -0
  157. package/dist/esm/types/general.js +1 -0
  158. package/dist/esm/types/index.d.ts +5 -0
  159. package/dist/esm/types/index.js +5 -0
  160. package/dist/esm/types/language.d.ts +227 -0
  161. package/dist/esm/types/language.js +228 -0
  162. package/dist/esm/types/theme.d.ts +18 -0
  163. package/dist/esm/types/theme.js +20 -0
  164. package/dist/esm/types/withSupportProps.d.ts +4 -0
  165. package/dist/esm/types/withSupportProps.js +1 -0
  166. package/dist/esm/utils/alert.d.ts +2 -0
  167. package/dist/esm/utils/alert.js +3 -0
  168. package/dist/esm/utils/createTextProvider.d.ts +2 -0
  169. package/dist/esm/utils/createTextProvider.js +13 -0
  170. package/dist/esm/utils/excludeSupportProps.d.ts +3 -0
  171. package/dist/esm/utils/excludeSupportProps.js +5 -0
  172. package/dist/esm/utils/extractSupportProps.d.ts +1 -0
  173. package/dist/esm/utils/extractSupportProps.js +5 -0
  174. package/dist/esm/utils/getAdaptive.d.ts +5 -0
  175. package/dist/esm/utils/getAdaptive.js +17 -0
  176. package/dist/esm/utils/getDisplayMode.d.ts +3 -0
  177. package/dist/esm/utils/getDisplayMode.js +25 -0
  178. package/dist/esm/utils/getMatchMedia.d.ts +10 -0
  179. package/dist/esm/utils/getMatchMedia.js +14 -0
  180. package/dist/esm/utils/getUserAgentInfo.d.ts +20 -0
  181. package/dist/esm/utils/getUserAgentInfo.js +26 -0
  182. package/dist/esm/utils/index.d.ts +10 -0
  183. package/dist/esm/utils/index.js +10 -0
  184. package/dist/esm/utils/keyboardSelectHandler.d.ts +2 -0
  185. package/dist/esm/utils/keyboardSelectHandler.js +7 -0
  186. package/dist/esm/utils/private/constants.d.ts +1 -0
  187. package/dist/esm/utils/private/constants.js +1 -0
  188. package/dist/esm/utils/private/excludeProps.d.ts +3 -0
  189. package/dist/esm/utils/private/excludeProps.js +5 -0
  190. package/dist/esm/utils/private/extractProps.d.ts +1 -0
  191. package/dist/esm/utils/private/extractProps.js +7 -0
  192. package/dist/esm/utils/uniqueId.d.ts +8 -0
  193. package/dist/esm/utils/uniqueId.js +10 -0
  194. package/package.json +3 -2
@@ -0,0 +1 @@
1
+ export * from './ConfigProvider';
@@ -0,0 +1,6 @@
1
+ import { ReactNode } from 'react';
2
+ export type ForThemeModeProps = {
3
+ light: ReactNode;
4
+ dark: ReactNode;
5
+ };
6
+ export declare function ForThemeMode(props: ForThemeModeProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,6 @@
1
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
+ import { useForThemeMode } from './hooks';
3
+ export function ForThemeMode(props) {
4
+ const jsx = useForThemeMode(props);
5
+ return _jsx(_Fragment, { children: jsx });
6
+ }
@@ -0,0 +1,6 @@
1
+ type UseForThemeModeParams<L, D> = {
2
+ light: L;
3
+ dark: D;
4
+ };
5
+ export declare function useForThemeMode<L, D>({ light, dark }: UseForThemeModeParams<L, D>): L | D;
6
+ export {};
@@ -0,0 +1,10 @@
1
+ import { useBrand, useTheme } from '../../hooks';
2
+ import { Brand, Themes } from '../../types/theme';
3
+ const DARK_THEMES = [Themes.GreenDark, Themes.PurpleDark];
4
+ const DARK_BRANDS = [Brand.CloudDark, Brand.MLSpaceDark, Brand.AdminDark, Brand.SiteDark, Brand.GigaIdDark];
5
+ export function useForThemeMode({ light, dark }) {
6
+ const { theme } = useTheme();
7
+ const { brand } = useBrand();
8
+ const isDarkTheme = DARK_THEMES.includes(theme) || DARK_BRANDS.includes(brand);
9
+ return isDarkTheme ? dark : light;
10
+ }
@@ -0,0 +1,2 @@
1
+ export * from './ForThemeMode';
2
+ export * from './hooks';
@@ -0,0 +1,2 @@
1
+ export * from './ForThemeMode';
2
+ export * from './hooks';
@@ -0,0 +1,2 @@
1
+ export * from './ConfigProvider';
2
+ export * from './ForThemeMode';
@@ -0,0 +1,2 @@
1
+ export * from './ConfigProvider';
2
+ export * from './ForThemeMode';
@@ -0,0 +1,34 @@
1
+ export declare const Adaptive: {
2
+ mobile: number;
3
+ tablet: number;
4
+ smallDesktop: number;
5
+ desktop: number;
6
+ };
7
+ export declare const CSS_BREAKPOINTS: {
8
+ mobile: string;
9
+ tablet: string;
10
+ smallDesktop: string;
11
+ desktop: string;
12
+ large: string;
13
+ };
14
+ export declare const LAYOUT_TYPE: {
15
+ readonly Mobile: "mobile";
16
+ readonly Tablet: "tablet";
17
+ readonly Desktop: "desktop";
18
+ readonly DesktopSmall: "desktopSmall";
19
+ };
20
+ export declare enum AdaptiveQueriesTitle {
21
+ IsMobile = "isMobile",
22
+ IsTablet = "isTablet",
23
+ IsSmallDesktop = "isSmallDesktop",
24
+ IsDesktop = "isDesktop",
25
+ IsLarge = "isLarge"
26
+ }
27
+ export declare const ADAPTIVE_QUERIES: Record<AdaptiveQueriesTitle, string>;
28
+ export declare const INITIAL_ADAPTIVE_QUERIES_VALUE: {
29
+ isMobile: boolean;
30
+ isTablet: boolean;
31
+ isSmallDesktop: boolean;
32
+ isDesktop: boolean;
33
+ isLarge: boolean;
34
+ };
@@ -0,0 +1,41 @@
1
+ export const Adaptive = {
2
+ mobile: 767,
3
+ tablet: 1023,
4
+ smallDesktop: 1279,
5
+ desktop: 1439,
6
+ };
7
+ export const CSS_BREAKPOINTS = {
8
+ mobile: `(max-width: ${Adaptive.mobile}px)`,
9
+ tablet: `(max-width: ${Adaptive.tablet}px)`,
10
+ smallDesktop: `(max-width: ${Adaptive.smallDesktop}px)`,
11
+ desktop: `(max-width: ${Adaptive.desktop}px)`,
12
+ large: `(min-width: ${Adaptive.desktop + 1}px)`,
13
+ };
14
+ export const LAYOUT_TYPE = {
15
+ Mobile: 'mobile',
16
+ Tablet: 'tablet',
17
+ Desktop: 'desktop',
18
+ DesktopSmall: 'desktopSmall',
19
+ };
20
+ export var AdaptiveQueriesTitle;
21
+ (function (AdaptiveQueriesTitle) {
22
+ AdaptiveQueriesTitle["IsMobile"] = "isMobile";
23
+ AdaptiveQueriesTitle["IsTablet"] = "isTablet";
24
+ AdaptiveQueriesTitle["IsSmallDesktop"] = "isSmallDesktop";
25
+ AdaptiveQueriesTitle["IsDesktop"] = "isDesktop";
26
+ AdaptiveQueriesTitle["IsLarge"] = "isLarge";
27
+ })(AdaptiveQueriesTitle || (AdaptiveQueriesTitle = {}));
28
+ export const ADAPTIVE_QUERIES = {
29
+ [AdaptiveQueriesTitle.IsMobile]: CSS_BREAKPOINTS.mobile,
30
+ [AdaptiveQueriesTitle.IsTablet]: CSS_BREAKPOINTS.tablet,
31
+ [AdaptiveQueriesTitle.IsSmallDesktop]: CSS_BREAKPOINTS.smallDesktop,
32
+ [AdaptiveQueriesTitle.IsDesktop]: CSS_BREAKPOINTS.desktop,
33
+ [AdaptiveQueriesTitle.IsLarge]: CSS_BREAKPOINTS.large,
34
+ };
35
+ export const INITIAL_ADAPTIVE_QUERIES_VALUE = {
36
+ [AdaptiveQueriesTitle.IsMobile]: false,
37
+ [AdaptiveQueriesTitle.IsTablet]: false,
38
+ [AdaptiveQueriesTitle.IsSmallDesktop]: false,
39
+ [AdaptiveQueriesTitle.IsDesktop]: false,
40
+ [AdaptiveQueriesTitle.IsLarge]: false,
41
+ };
@@ -0,0 +1,16 @@
1
+ import { MatchMediaGeneric } from '../types';
2
+ export declare const DISPLAY_MODES: {
3
+ Browser: string;
4
+ Pwa: string;
5
+ Fullscreen: string;
6
+ MinimalUI: string;
7
+ WindowControlsOverlay: string;
8
+ };
9
+ export declare const DISPLAY_MODE_QUERIES: {
10
+ isBrowser: string;
11
+ isPwa: string;
12
+ isFullscreen: string;
13
+ isMinimalUI: string;
14
+ isWindowControlsOverlay: string;
15
+ };
16
+ export declare const INITIAL_DISPLAY_MODE_QUERIES_VALUE: MatchMediaGeneric<keyof typeof DISPLAY_MODE_QUERIES>;
@@ -0,0 +1,21 @@
1
+ export const DISPLAY_MODES = {
2
+ Browser: 'browser',
3
+ Pwa: 'pwa',
4
+ Fullscreen: 'fullscreen',
5
+ MinimalUI: 'minimal-ui',
6
+ WindowControlsOverlay: 'window-controls-overlay',
7
+ };
8
+ export const DISPLAY_MODE_QUERIES = {
9
+ isBrowser: `(display-mode: browser)`,
10
+ isPwa: `(display-mode: standalone)`,
11
+ isFullscreen: `(display-mode: fullscreen)`,
12
+ isMinimalUI: `(display-mode: minimal-ui)`,
13
+ isWindowControlsOverlay: `(display-mode: window-controls-overlay)`,
14
+ };
15
+ export const INITIAL_DISPLAY_MODE_QUERIES_VALUE = {
16
+ isBrowser: false,
17
+ isPwa: false,
18
+ isFullscreen: false,
19
+ isMinimalUI: false,
20
+ isWindowControlsOverlay: false,
21
+ };
@@ -0,0 +1,14 @@
1
+ import { Brand, LanguageCodeType, Themes } from '../types';
2
+ export declare const DEFAULT: {
3
+ LANGUAGE: LanguageCodeType;
4
+ BRAND: Brand;
5
+ THEME: Themes;
6
+ };
7
+ export declare enum POST_MESSAGE_KEY {
8
+ changeTheme = "changeTheme",
9
+ changeThemeDone = "changeThemeDone",
10
+ changeBrand = "changeBrand",
11
+ changeBrandDone = "changeBrandDone",
12
+ changeLanguage = "changeLanguage",
13
+ changeLanguageDone = "changeLanguageDone"
14
+ }
@@ -0,0 +1,15 @@
1
+ import { Brand, LanguageCodeType, Themes } from '../types';
2
+ export const DEFAULT = {
3
+ LANGUAGE: LanguageCodeType.ruRU,
4
+ BRAND: Brand.Cloud,
5
+ THEME: Themes.Purple,
6
+ };
7
+ export var POST_MESSAGE_KEY;
8
+ (function (POST_MESSAGE_KEY) {
9
+ POST_MESSAGE_KEY["changeTheme"] = "changeTheme";
10
+ POST_MESSAGE_KEY["changeThemeDone"] = "changeThemeDone";
11
+ POST_MESSAGE_KEY["changeBrand"] = "changeBrand";
12
+ POST_MESSAGE_KEY["changeBrandDone"] = "changeBrandDone";
13
+ POST_MESSAGE_KEY["changeLanguage"] = "changeLanguage";
14
+ POST_MESSAGE_KEY["changeLanguageDone"] = "changeLanguageDone";
15
+ })(POST_MESSAGE_KEY || (POST_MESSAGE_KEY = {}));
@@ -0,0 +1 @@
1
+ export declare function tryParseJson<T>(value: T): T | Record<string, unknown>;
@@ -0,0 +1,12 @@
1
+ function isValidJson(value) {
2
+ try {
3
+ JSON.parse(value);
4
+ return true;
5
+ }
6
+ catch (_a) {
7
+ return false;
8
+ }
9
+ }
10
+ export function tryParseJson(value) {
11
+ return typeof value === 'string' && isValidJson(value) ? JSON.parse(value) : value;
12
+ }
@@ -0,0 +1,13 @@
1
+ export * from './useLanguage';
2
+ export * from './useComponentSize';
3
+ export * from './useTheme';
4
+ export * from './useBrand';
5
+ export * from './useForceUpdate';
6
+ export * from './useForceUpdateOnPageLoadedCompletely';
7
+ export * from './useEventHandler';
8
+ export * from './useUniqueId';
9
+ export * from './useConfig';
10
+ export * from './useTextProvider';
11
+ export * from './useAdaptive';
12
+ export * from './useDisplayMode';
13
+ export * from './useMatchMedia';
@@ -0,0 +1,13 @@
1
+ export * from './useLanguage';
2
+ export * from './useComponentSize';
3
+ export * from './useTheme';
4
+ export * from './useBrand';
5
+ export * from './useForceUpdate';
6
+ export * from './useForceUpdateOnPageLoadedCompletely';
7
+ export * from './useEventHandler';
8
+ export * from './useUniqueId';
9
+ export * from './useConfig';
10
+ export * from './useTextProvider';
11
+ export * from './useAdaptive';
12
+ export * from './useDisplayMode';
13
+ export * from './useMatchMedia';
@@ -0,0 +1,2 @@
1
+ import { WindowStore } from '../../types';
2
+ export declare function getCustomStore(defaultStore?: Partial<WindowStore['sbercloudUIKit']>): WindowStore['sbercloudUIKit'];
@@ -0,0 +1,8 @@
1
+ import { DEFAULT } from '../../constants/environment';
2
+ export function getCustomStore(defaultStore = {}) {
3
+ const customWindow = globalThis;
4
+ if (!customWindow.sbercloudUIKit) {
5
+ customWindow.sbercloudUIKit = Object.assign({ brand: DEFAULT.BRAND, theme: DEFAULT.THEME, languageCode: DEFAULT.LANGUAGE }, defaultStore);
6
+ }
7
+ return customWindow.sbercloudUIKit;
8
+ }
@@ -0,0 +1,4 @@
1
+ import { LayoutType } from '../types/adaptive';
2
+ export declare function useAdaptive(): {
3
+ layoutType: LayoutType;
4
+ };
@@ -0,0 +1,6 @@
1
+ import { getAdaptive } from '../utils';
2
+ import { useAdaptiveMatchMedia } from './useMatchMedia';
3
+ export function useAdaptive() {
4
+ const matchMedia = useAdaptiveMatchMedia();
5
+ return getAdaptive(matchMedia);
6
+ }
@@ -0,0 +1,5 @@
1
+ import { Brand } from '../types/theme';
2
+ export declare const useBrand: () => {
3
+ brand: Brand;
4
+ changeBrand: (brand: Brand) => void;
5
+ };
@@ -0,0 +1,24 @@
1
+ import { useCallback, useEffect, useState } from 'react';
2
+ import { isBrowser } from '@snack-uikit/utils';
3
+ import { DEFAULT, POST_MESSAGE_KEY } from '../constants/environment';
4
+ import { tryParseJson } from '../helpers/tryParseJson';
5
+ import { getCustomStore } from './private/getCustomStore';
6
+ export const useBrand = () => {
7
+ const store = getCustomStore();
8
+ const [brand, setBrand] = useState(store.brand || DEFAULT.BRAND);
9
+ useEffect(() => {
10
+ const receiveChangeThemeDoneMessage = (event) => {
11
+ const eventData = tryParseJson(event.data);
12
+ if (eventData.key !== POST_MESSAGE_KEY.changeBrandDone)
13
+ return;
14
+ setBrand(eventData.value);
15
+ };
16
+ window.addEventListener('message', receiveChangeThemeDoneMessage, false);
17
+ return () => window.removeEventListener('message', receiveChangeThemeDoneMessage, false);
18
+ }, []);
19
+ const changeBrand = useCallback((brand) => {
20
+ isBrowser() &&
21
+ window.postMessage(JSON.stringify({ key: POST_MESSAGE_KEY.changeBrand, value: brand }), location.origin);
22
+ }, []);
23
+ return { brand, changeBrand };
24
+ };
@@ -0,0 +1,5 @@
1
+ import { RefObject } from 'react';
2
+ export declare function useComponentSize(ref: RefObject<HTMLElement>): {
3
+ width: number;
4
+ height: number;
5
+ };
@@ -0,0 +1,33 @@
1
+ import { useCallback, useState } from 'react';
2
+ import { useLayoutEffect } from '@snack-uikit/utils';
3
+ function getSize(el) {
4
+ if (!el) {
5
+ return {
6
+ width: 0,
7
+ height: 0,
8
+ };
9
+ }
10
+ return {
11
+ width: el.offsetWidth,
12
+ height: el.offsetHeight,
13
+ };
14
+ }
15
+ export function useComponentSize(ref) {
16
+ const [size, setSize] = useState(getSize(ref.current));
17
+ const handleResize = useCallback(() => {
18
+ if (ref.current) {
19
+ setSize(getSize(ref.current));
20
+ }
21
+ }, [ref]);
22
+ useLayoutEffect(() => {
23
+ if (!ref.current)
24
+ return;
25
+ handleResize();
26
+ const resizeObserver = new ResizeObserver(handleResize);
27
+ resizeObserver.observe(ref.current);
28
+ return () => {
29
+ resizeObserver.disconnect();
30
+ };
31
+ }, [handleResize, ref]);
32
+ return size;
33
+ }
@@ -0,0 +1,8 @@
1
+ import { Brand, LanguageCodeType, Themes } from '../types';
2
+ type UseConfigProps = {
3
+ languageCode?: LanguageCodeType;
4
+ theme?: Themes;
5
+ brand?: Brand;
6
+ };
7
+ export declare function useConfig({ languageCode, theme, brand }: UseConfigProps): void;
8
+ export {};
@@ -0,0 +1,120 @@
1
+ import { useCallback, useEffect, useRef, useState } from 'react';
2
+ import AdminBrandThemes from '@sbercloud/figma-tokens-admin/build/css/brand.module.css';
3
+ import CloudBrandThemes from '@sbercloud/figma-tokens-cloud-platform/build/css/brand.module.css';
4
+ import GigaIdBrandThemes from '@sbercloud/figma-tokens-giga-id/build/css/brand.module.css';
5
+ import MLSpaceBrandThemes from '@sbercloud/figma-tokens-mlspace/build/css/brand.module.css';
6
+ import SiteBrandThemes from '@sbercloud/figma-tokens-web/build/css/brand.module.css';
7
+ import { isBrowser, useLayoutEffect } from '@snack-uikit/utils';
8
+ import { POST_MESSAGE_KEY } from '../constants/environment';
9
+ import { tryParseJson } from '../helpers/tryParseJson';
10
+ import { Brand, Themes } from '../types';
11
+ import { getCustomStore } from './private/getCustomStore';
12
+ const themeMap = {
13
+ [Themes.Green]: CloudBrandThemes.light,
14
+ [Themes.GreenDark]: CloudBrandThemes.dark,
15
+ [Themes.Purple]: MLSpaceBrandThemes.light,
16
+ [Themes.PurpleDark]: MLSpaceBrandThemes.dark,
17
+ };
18
+ const brandMap = {
19
+ [Brand.Cloud]: CloudBrandThemes.light,
20
+ [Brand.CloudDark]: CloudBrandThemes.dark,
21
+ [Brand.MLSpace]: MLSpaceBrandThemes.light,
22
+ [Brand.MLSpaceDark]: MLSpaceBrandThemes.dark,
23
+ [Brand.Admin]: AdminBrandThemes.light,
24
+ [Brand.AdminDark]: AdminBrandThemes.dark,
25
+ [Brand.Site]: SiteBrandThemes.light,
26
+ [Brand.SiteDark]: SiteBrandThemes.dark,
27
+ [Brand.GigaId]: GigaIdBrandThemes.light,
28
+ [Brand.GigaIdDark]: GigaIdBrandThemes.dark,
29
+ };
30
+ export function useConfig({ languageCode, theme, brand }) {
31
+ const store = getCustomStore({ brand, theme, languageCode });
32
+ const [configLanguageCode, setConfigLanguageCodeTheme] = useState(store.languageCode);
33
+ const previousThemeRef = useRef();
34
+ const previousBrandRef = useRef();
35
+ const updateTheme = useCallback((newTheme) => {
36
+ if (isBrowser()) {
37
+ store.theme = newTheme;
38
+ const html = document.getElementsByTagName('html')[0];
39
+ if (previousThemeRef.current) {
40
+ html.classList.remove(themeMap[previousThemeRef.current]);
41
+ }
42
+ html.setAttribute('data-theme', newTheme);
43
+ const body = document.getElementsByTagName('body')[0];
44
+ body.setAttribute('data-theme', newTheme);
45
+ html.classList.add(themeMap[newTheme]);
46
+ window.postMessage(JSON.stringify({ key: POST_MESSAGE_KEY.changeThemeDone, value: newTheme }), location.origin);
47
+ previousThemeRef.current = newTheme;
48
+ }
49
+ }, [store]);
50
+ const updateBrand = useCallback((newBrand) => {
51
+ if (isBrowser()) {
52
+ store.brand = newBrand;
53
+ const html = document.getElementsByTagName('html')[0];
54
+ if (previousBrandRef.current) {
55
+ html.classList.remove(brandMap[previousBrandRef.current]);
56
+ }
57
+ html.setAttribute('data-brand', newBrand);
58
+ const body = document.getElementsByTagName('body')[0];
59
+ body.setAttribute('data-brand', newBrand);
60
+ html.classList.add(brandMap[newBrand]);
61
+ window.postMessage(JSON.stringify({ key: POST_MESSAGE_KEY.changeBrandDone, value: newBrand }), location.origin);
62
+ previousBrandRef.current = newBrand;
63
+ }
64
+ }, [store]);
65
+ useEffect(() => {
66
+ /*-----------
67
+ --- THEME/BRAND ---
68
+ -----------*/
69
+ const receiveChangeThemeMessage = (event) => {
70
+ const eventData = tryParseJson(event.data);
71
+ switch (eventData.key) {
72
+ case POST_MESSAGE_KEY.changeTheme:
73
+ updateTheme(eventData.value);
74
+ break;
75
+ case POST_MESSAGE_KEY.changeBrand:
76
+ updateBrand(eventData.value);
77
+ break;
78
+ default:
79
+ return;
80
+ }
81
+ };
82
+ window.addEventListener('message', receiveChangeThemeMessage, false);
83
+ /*--------------
84
+ --- LANGUAGE ---
85
+ --------------*/
86
+ const receiveChangeLanguageMessage = (event) => {
87
+ const eventData = tryParseJson(event.data);
88
+ if (eventData.key !== POST_MESSAGE_KEY.changeLanguage)
89
+ return;
90
+ setConfigLanguageCodeTheme(eventData.value);
91
+ };
92
+ window.addEventListener('message', receiveChangeLanguageMessage, false);
93
+ return () => {
94
+ window.removeEventListener('message', receiveChangeThemeMessage, false);
95
+ window.removeEventListener('message', receiveChangeLanguageMessage, false);
96
+ };
97
+ }, [updateBrand, updateTheme]);
98
+ /*-------------
99
+ ---- THEME ----
100
+ -------------*/
101
+ // need to do it this way to update theme before any other child component render & useEffect/useLayoutEffect
102
+ if (previousThemeRef.current !== theme && theme) {
103
+ updateTheme(theme);
104
+ }
105
+ if (previousBrandRef.current !== brand && brand) {
106
+ updateBrand(brand);
107
+ }
108
+ /*--------------
109
+ --- LANGUAGE ---
110
+ --------------*/
111
+ useLayoutEffect(() => {
112
+ if (languageCode) {
113
+ store.languageCode = languageCode;
114
+ setConfigLanguageCodeTheme(store.languageCode);
115
+ }
116
+ }, [languageCode, store]);
117
+ useEffect(() => {
118
+ window.postMessage(JSON.stringify({ key: POST_MESSAGE_KEY.changeLanguageDone, value: configLanguageCode }), location.origin);
119
+ }, [configLanguageCode]);
120
+ }
@@ -0,0 +1,3 @@
1
+ import { ValueOf } from '@snack-uikit/utils';
2
+ import { DISPLAY_MODES } from '../constants/displayMode';
3
+ export declare function useDisplayMode(): 'unknown' | 'twa' | ValueOf<typeof DISPLAY_MODES>;
@@ -0,0 +1,6 @@
1
+ import { getDisplayMode } from '../utils/getDisplayMode';
2
+ import { useDisplayModeMatchMedia } from './useMatchMedia';
3
+ export function useDisplayMode() {
4
+ const matchMedia = useDisplayModeMatchMedia();
5
+ return getDisplayMode(matchMedia);
6
+ }
@@ -0,0 +1 @@
1
+ export declare function useEventHandler<T extends (...args: never[]) => unknown>(handler: T): T;
@@ -0,0 +1,14 @@
1
+ import { useCallback, useRef } from 'react';
2
+ import { useLayoutEffect } from '@snack-uikit/utils';
3
+ import { warning } from '../utils';
4
+ export function useEventHandler(handler) {
5
+ const handlerRef = useRef(null);
6
+ useLayoutEffect(() => {
7
+ handlerRef.current = handler;
8
+ });
9
+ return useCallback((...args) => {
10
+ const handler = handlerRef.current;
11
+ warning('The event handler cannot be called during render', handler === null);
12
+ return handler === null || handler === void 0 ? void 0 : handler(...args);
13
+ }, []);
14
+ }
@@ -0,0 +1 @@
1
+ export declare function useForceUpdate(): () => void;
@@ -0,0 +1,5 @@
1
+ import { useCallback, useState } from 'react';
2
+ export function useForceUpdate() {
3
+ const [, setVersion] = useState(0);
4
+ return useCallback(() => setVersion(version => version + 1), []);
5
+ }
@@ -0,0 +1 @@
1
+ export declare function useForceUpdateOnPageLoadedCompletely(): void;
@@ -0,0 +1,11 @@
1
+ import { useEffect } from 'react';
2
+ import { useForceUpdate } from './useForceUpdate';
3
+ export function useForceUpdateOnPageLoadedCompletely() {
4
+ const rerender = useForceUpdate();
5
+ useEffect(() => {
6
+ window.addEventListener('load', rerender);
7
+ return () => {
8
+ window.removeEventListener('load', rerender);
9
+ };
10
+ }, [rerender]);
11
+ }
@@ -0,0 +1,9 @@
1
+ import { LanguageCodeType } from '../types';
2
+ type useLanguageProps = {
3
+ onlyEnabledLanguage?: boolean;
4
+ };
5
+ export declare const useLanguage: (props?: useLanguageProps) => {
6
+ languageCode: LanguageCodeType;
7
+ changeLanguage: (languageCode: LanguageCodeType) => void;
8
+ };
9
+ export {};
@@ -0,0 +1,48 @@
1
+ import { useCallback, useEffect, useState } from 'react';
2
+ import { isBrowser, useLayoutEffect } from '@snack-uikit/utils';
3
+ import { DEFAULT, POST_MESSAGE_KEY } from '../constants/environment';
4
+ import { tryParseJson } from '../helpers/tryParseJson';
5
+ import { LanguageCodeType } from '../types';
6
+ import { getCustomStore } from './private/getCustomStore';
7
+ export const useLanguage = (props) => {
8
+ const store = getCustomStore();
9
+ const [languageCode, setLanguageCode] = useState(store.languageCode || DEFAULT.LANGUAGE);
10
+ const onlyEnabledLanguage = props === null || props === void 0 ? void 0 : props.onlyEnabledLanguage;
11
+ useEffect(() => {
12
+ const receiveChangeLanguageDoneMessage = (event) => {
13
+ const eventData = tryParseJson(event.data);
14
+ if (eventData.key !== POST_MESSAGE_KEY.changeLanguageDone)
15
+ return;
16
+ setLanguageCode(eventData.value);
17
+ };
18
+ window.addEventListener('message', receiveChangeLanguageDoneMessage, false);
19
+ return () => window.removeEventListener('message', receiveChangeLanguageDoneMessage, false);
20
+ }, []);
21
+ useLayoutEffect(() => {
22
+ if (!onlyEnabledLanguage) {
23
+ return;
24
+ }
25
+ const miniCode = languageCode.split('-')[0];
26
+ const enGroup = miniCode === 'en';
27
+ const ruGroup = ['ru', 'be'].includes(miniCode);
28
+ if (enGroup) {
29
+ setLanguageCode(LanguageCodeType.enGB);
30
+ return;
31
+ }
32
+ if (ruGroup) {
33
+ setLanguageCode(LanguageCodeType.ruRU);
34
+ return;
35
+ }
36
+ if (languageCode === LanguageCodeType.cimode) {
37
+ setLanguageCode(LanguageCodeType.cimode);
38
+ return;
39
+ }
40
+ setLanguageCode(LanguageCodeType.ruRU);
41
+ }, [languageCode, onlyEnabledLanguage]);
42
+ const changeLanguage = useCallback((languageCode) => {
43
+ if (isBrowser()) {
44
+ window.postMessage(JSON.stringify({ key: POST_MESSAGE_KEY.changeLanguage, value: languageCode }), location.origin);
45
+ }
46
+ }, []);
47
+ return { languageCode, changeLanguage };
48
+ };
@@ -0,0 +1,7 @@
1
+ import { MatchMediaGeneric } from '../types';
2
+ export declare const useMatchMediaGeneric: <T extends string>({ queryValues, initialValues, }: {
3
+ queryValues: Record<T, string>;
4
+ initialValues: MatchMediaGeneric<T>;
5
+ }) => MatchMediaGeneric<T>;
6
+ export declare function useAdaptiveMatchMedia(): MatchMediaGeneric<import("../constants/adaptive").AdaptiveQueriesTitle>;
7
+ export declare function useDisplayModeMatchMedia(): MatchMediaGeneric<"isBrowser" | "isPwa" | "isFullscreen" | "isMinimalUI" | "isWindowControlsOverlay">;
@@ -0,0 +1,33 @@
1
+ import { useRef, useState } from 'react';
2
+ import { useLayoutEffect } from '@snack-uikit/utils';
3
+ import { ADAPTIVE_QUERIES, INITIAL_ADAPTIVE_QUERIES_VALUE } from '../constants/adaptive';
4
+ import { DISPLAY_MODE_QUERIES, INITIAL_DISPLAY_MODE_QUERIES_VALUE } from '../constants/displayMode';
5
+ import { getMatchMediaGeneric, getMediaQueryListGeneric } from '../utils/getMatchMedia';
6
+ export const useMatchMediaGeneric = ({ queryValues, initialValues, }) => {
7
+ const updatedHandlers = {
8
+ getMatchMedia: () => getMatchMediaGeneric({ queryValues, initialValues }),
9
+ getMediaQueryList: () => getMediaQueryListGeneric({ queryValues }),
10
+ };
11
+ const handlersRef = useRef(updatedHandlers);
12
+ handlersRef.current = updatedHandlers;
13
+ const [value, setValue] = useState(handlersRef.current.getMatchMedia);
14
+ useLayoutEffect(() => {
15
+ const handler = () => setValue(handlersRef.current.getMatchMedia);
16
+ const mediaQueryList = handlersRef.current.getMediaQueryList();
17
+ mediaQueryList.forEach(([, mql]) => mql.addEventListener('change', handler));
18
+ return () => mediaQueryList.forEach(([, mql]) => mql.removeEventListener('change', handler));
19
+ }, []);
20
+ return value;
21
+ };
22
+ export function useAdaptiveMatchMedia() {
23
+ return useMatchMediaGeneric({
24
+ queryValues: ADAPTIVE_QUERIES,
25
+ initialValues: INITIAL_ADAPTIVE_QUERIES_VALUE,
26
+ });
27
+ }
28
+ export function useDisplayModeMatchMedia() {
29
+ return useMatchMediaGeneric({
30
+ queryValues: DISPLAY_MODE_QUERIES,
31
+ initialValues: INITIAL_DISPLAY_MODE_QUERIES_VALUE,
32
+ });
33
+ }
@@ -0,0 +1,4 @@
1
+ import { LanguageCodeType } from '../types';
2
+ type TextProviderFunction<T extends string> = (entity: T) => string;
3
+ export declare const useTextProvider: <T extends string>(textProvider: (language: LanguageCodeType, entity: T) => string) => TextProviderFunction<T>;
4
+ export {};