@gravity-ui/dashkit 3.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 (232) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/LICENSE +21 -0
  3. package/README.md +364 -0
  4. package/build/cjs/components/DashKit/DashKit.d.ts +50 -0
  5. package/build/cjs/components/DashKit/DashKit.js +70 -0
  6. package/build/cjs/components/DashKit/index.d.ts +1 -0
  7. package/build/cjs/components/DashKit/index.js +4 -0
  8. package/build/cjs/components/DashKitView/DashKitView.css +4 -0
  9. package/build/cjs/components/DashKitView/DashKitView.d.ts +3 -0
  10. package/build/cjs/components/DashKitView/DashKitView.js +23 -0
  11. package/build/cjs/components/GridItem/GridItem.css +83 -0
  12. package/build/cjs/components/GridItem/GridItem.d.ts +3 -0
  13. package/build/cjs/components/GridItem/GridItem.js +70 -0
  14. package/build/cjs/components/GridLayout/GridLayout.d.ts +25 -0
  15. package/build/cjs/components/GridLayout/GridLayout.js +89 -0
  16. package/build/cjs/components/Item/Item.css +19 -0
  17. package/build/cjs/components/Item/Item.d.ts +67 -0
  18. package/build/cjs/components/Item/Item.js +23 -0
  19. package/build/cjs/components/MobileLayout/MobileLayout.css +10 -0
  20. package/build/cjs/components/MobileLayout/MobileLayout.d.ts +16 -0
  21. package/build/cjs/components/MobileLayout/MobileLayout.js +54 -0
  22. package/build/cjs/components/MobileLayout/helpers.d.ts +3 -0
  23. package/build/cjs/components/MobileLayout/helpers.js +32 -0
  24. package/build/cjs/components/OverlayControls/OverlayControls.css +28 -0
  25. package/build/cjs/components/OverlayControls/OverlayControls.d.ts +54 -0
  26. package/build/cjs/components/OverlayControls/OverlayControls.js +212 -0
  27. package/build/cjs/components/index.d.ts +1 -0
  28. package/build/cjs/components/index.js +4 -0
  29. package/build/cjs/constants/common.d.ts +7 -0
  30. package/build/cjs/constants/common.js +10 -0
  31. package/build/cjs/constants/index.d.ts +1 -0
  32. package/build/cjs/constants/index.js +4 -0
  33. package/build/cjs/context/DashKitContext.d.ts +2 -0
  34. package/build/cjs/context/DashKitContext.js +7 -0
  35. package/build/cjs/hocs/prepareItem.d.ts +66 -0
  36. package/build/cjs/hocs/prepareItem.js +66 -0
  37. package/build/cjs/hocs/withContext.d.ts +165 -0
  38. package/build/cjs/hocs/withContext.js +203 -0
  39. package/build/cjs/hooks/useCalcLayout.d.ts +13 -0
  40. package/build/cjs/hooks/useCalcLayout.js +31 -0
  41. package/build/cjs/i18n/en.json +8 -0
  42. package/build/cjs/i18n/index.d.ts +4 -0
  43. package/build/cjs/i18n/index.js +19 -0
  44. package/build/cjs/i18n/ru.json +8 -0
  45. package/build/cjs/icons/CloseIcon.d.ts +2 -0
  46. package/build/cjs/icons/CloseIcon.js +10 -0
  47. package/build/cjs/icons/CogIcon.d.ts +2 -0
  48. package/build/cjs/icons/CogIcon.js +10 -0
  49. package/build/cjs/icons/CopyIcon.d.ts +2 -0
  50. package/build/cjs/icons/CopyIcon.js +10 -0
  51. package/build/cjs/icons/DeleteIcon.d.ts +2 -0
  52. package/build/cjs/icons/DeleteIcon.js +12 -0
  53. package/build/cjs/icons/DotsIcon.d.ts +2 -0
  54. package/build/cjs/icons/DotsIcon.js +10 -0
  55. package/build/cjs/icons/TickIcon.d.ts +2 -0
  56. package/build/cjs/icons/TickIcon.js +10 -0
  57. package/build/cjs/icons/WarningIcon.d.ts +2 -0
  58. package/build/cjs/icons/WarningIcon.js +10 -0
  59. package/build/cjs/index.d.ts +5 -0
  60. package/build/cjs/index.js +8 -0
  61. package/build/cjs/plugins/Text/Text.css +34 -0
  62. package/build/cjs/plugins/Text/Text.d.ts +52 -0
  63. package/build/cjs/plugins/Text/Text.js +119 -0
  64. package/build/cjs/plugins/Title/Title.css +24 -0
  65. package/build/cjs/plugins/Title/Title.d.ts +14 -0
  66. package/build/cjs/plugins/Title/Title.js +25 -0
  67. package/build/cjs/shared/constants/common.d.ts +2 -0
  68. package/build/cjs/shared/constants/common.js +5 -0
  69. package/build/cjs/shared/constants/index.d.ts +1 -0
  70. package/build/cjs/shared/constants/index.js +4 -0
  71. package/build/cjs/shared/index.d.ts +4 -0
  72. package/build/cjs/shared/index.js +7 -0
  73. package/build/cjs/shared/modules/__tests__/helpers.test.d.ts +1 -0
  74. package/build/cjs/shared/modules/__tests__/helpers.test.js +217 -0
  75. package/build/cjs/shared/modules/helpers.d.ts +42 -0
  76. package/build/cjs/shared/modules/helpers.js +172 -0
  77. package/build/cjs/shared/modules/index.d.ts +2 -0
  78. package/build/cjs/shared/modules/index.js +5 -0
  79. package/build/cjs/shared/modules/state-and-params.d.ts +16 -0
  80. package/build/cjs/shared/modules/state-and-params.js +94 -0
  81. package/build/cjs/shared/types/common.d.ts +5 -0
  82. package/build/cjs/shared/types/common.js +2 -0
  83. package/build/cjs/shared/types/config.d.ts +49 -0
  84. package/build/cjs/shared/types/config.js +2 -0
  85. package/build/cjs/shared/types/index.d.ts +4 -0
  86. package/build/cjs/shared/types/index.js +7 -0
  87. package/build/cjs/shared/types/plugin.d.ts +8 -0
  88. package/build/cjs/shared/types/plugin.js +2 -0
  89. package/build/cjs/shared/types/state-and-params.d.ts +22 -0
  90. package/build/cjs/shared/types/state-and-params.js +3 -0
  91. package/build/cjs/shared/units/__tests__/state-and-params.test.d.ts +241 -0
  92. package/build/cjs/shared/units/__tests__/state-and-params.test.js +299 -0
  93. package/build/cjs/shared/units/datalens/index.d.ts +5 -0
  94. package/build/cjs/shared/units/datalens/index.js +25 -0
  95. package/build/cjs/shared/units/index.d.ts +1 -0
  96. package/build/cjs/shared/units/index.js +4 -0
  97. package/build/cjs/typings/common.d.ts +32 -0
  98. package/build/cjs/typings/common.js +2 -0
  99. package/build/cjs/typings/config.d.ts +7 -0
  100. package/build/cjs/typings/config.js +2 -0
  101. package/build/cjs/typings/global.d.ts +7 -0
  102. package/build/cjs/typings/index.d.ts +3 -0
  103. package/build/cjs/typings/index.js +6 -0
  104. package/build/cjs/typings/plugin.d.ts +39 -0
  105. package/build/cjs/typings/plugin.js +2 -0
  106. package/build/cjs/utils/__tests__/mock.test.d.ts +1 -0
  107. package/build/cjs/utils/__tests__/mock.test.js +8 -0
  108. package/build/cjs/utils/configure.d.ts +9 -0
  109. package/build/cjs/utils/configure.js +21 -0
  110. package/build/cjs/utils/i18n.d.ts +7 -0
  111. package/build/cjs/utils/i18n.js +13 -0
  112. package/build/cjs/utils/index.d.ts +3 -0
  113. package/build/cjs/utils/index.js +6 -0
  114. package/build/cjs/utils/register-manager.d.ts +46 -0
  115. package/build/cjs/utils/register-manager.js +58 -0
  116. package/build/cjs/utils/update-manager.d.ts +37 -0
  117. package/build/cjs/utils/update-manager.js +274 -0
  118. package/build/esm/components/DashKit/DashKit.d.ts +50 -0
  119. package/build/esm/components/DashKit/DashKit.js +65 -0
  120. package/build/esm/components/DashKit/index.d.ts +1 -0
  121. package/build/esm/components/DashKit/index.js +1 -0
  122. package/build/esm/components/DashKitView/DashKitView.css +4 -0
  123. package/build/esm/components/DashKitView/DashKitView.d.ts +3 -0
  124. package/build/esm/components/DashKitView/DashKitView.js +21 -0
  125. package/build/esm/components/GridItem/GridItem.css +83 -0
  126. package/build/esm/components/GridItem/GridItem.d.ts +3 -0
  127. package/build/esm/components/GridItem/GridItem.js +68 -0
  128. package/build/esm/components/GridLayout/GridLayout.d.ts +25 -0
  129. package/build/esm/components/GridLayout/GridLayout.js +85 -0
  130. package/build/esm/components/Item/Item.css +19 -0
  131. package/build/esm/components/Item/Item.d.ts +67 -0
  132. package/build/esm/components/Item/Item.js +21 -0
  133. package/build/esm/components/MobileLayout/MobileLayout.css +10 -0
  134. package/build/esm/components/MobileLayout/MobileLayout.d.ts +16 -0
  135. package/build/esm/components/MobileLayout/MobileLayout.js +51 -0
  136. package/build/esm/components/MobileLayout/helpers.d.ts +3 -0
  137. package/build/esm/components/MobileLayout/helpers.js +28 -0
  138. package/build/esm/components/OverlayControls/OverlayControls.css +28 -0
  139. package/build/esm/components/OverlayControls/OverlayControls.d.ts +55 -0
  140. package/build/esm/components/OverlayControls/OverlayControls.js +209 -0
  141. package/build/esm/components/index.d.ts +1 -0
  142. package/build/esm/components/index.js +1 -0
  143. package/build/esm/constants/common.d.ts +7 -0
  144. package/build/esm/constants/common.js +7 -0
  145. package/build/esm/constants/index.d.ts +1 -0
  146. package/build/esm/constants/index.js +1 -0
  147. package/build/esm/context/DashKitContext.d.ts +2 -0
  148. package/build/esm/context/DashKitContext.js +3 -0
  149. package/build/esm/hocs/prepareItem.d.ts +66 -0
  150. package/build/esm/hocs/prepareItem.js +61 -0
  151. package/build/esm/hocs/withContext.d.ts +165 -0
  152. package/build/esm/hocs/withContext.js +198 -0
  153. package/build/esm/hooks/useCalcLayout.d.ts +13 -0
  154. package/build/esm/hooks/useCalcLayout.js +26 -0
  155. package/build/esm/i18n/en.json +8 -0
  156. package/build/esm/i18n/index.d.ts +4 -0
  157. package/build/esm/i18n/index.js +15 -0
  158. package/build/esm/i18n/ru.json +8 -0
  159. package/build/esm/icons/CloseIcon.d.ts +2 -0
  160. package/build/esm/icons/CloseIcon.js +5 -0
  161. package/build/esm/icons/CogIcon.d.ts +2 -0
  162. package/build/esm/icons/CogIcon.js +5 -0
  163. package/build/esm/icons/CopyIcon.d.ts +2 -0
  164. package/build/esm/icons/CopyIcon.js +5 -0
  165. package/build/esm/icons/DeleteIcon.d.ts +2 -0
  166. package/build/esm/icons/DeleteIcon.js +7 -0
  167. package/build/esm/icons/DotsIcon.d.ts +2 -0
  168. package/build/esm/icons/DotsIcon.js +5 -0
  169. package/build/esm/icons/TickIcon.d.ts +2 -0
  170. package/build/esm/icons/TickIcon.js +5 -0
  171. package/build/esm/icons/WarningIcon.d.ts +2 -0
  172. package/build/esm/icons/WarningIcon.js +5 -0
  173. package/build/esm/index.d.ts +5 -0
  174. package/build/esm/index.js +5 -0
  175. package/build/esm/plugins/Text/Text.css +34 -0
  176. package/build/esm/plugins/Text/Text.d.ts +53 -0
  177. package/build/esm/plugins/Text/Text.js +115 -0
  178. package/build/esm/plugins/Title/Title.css +24 -0
  179. package/build/esm/plugins/Title/Title.d.ts +15 -0
  180. package/build/esm/plugins/Title/Title.js +21 -0
  181. package/build/esm/shared/constants/common.d.ts +2 -0
  182. package/build/esm/shared/constants/common.js +2 -0
  183. package/build/esm/shared/constants/index.d.ts +1 -0
  184. package/build/esm/shared/constants/index.js +1 -0
  185. package/build/esm/shared/index.d.ts +4 -0
  186. package/build/esm/shared/index.js +4 -0
  187. package/build/esm/shared/modules/__tests__/helpers.test.d.ts +1 -0
  188. package/build/esm/shared/modules/__tests__/helpers.test.js +215 -0
  189. package/build/esm/shared/modules/helpers.d.ts +42 -0
  190. package/build/esm/shared/modules/helpers.js +157 -0
  191. package/build/esm/shared/modules/index.d.ts +2 -0
  192. package/build/esm/shared/modules/index.js +2 -0
  193. package/build/esm/shared/modules/state-and-params.d.ts +16 -0
  194. package/build/esm/shared/modules/state-and-params.js +87 -0
  195. package/build/esm/shared/types/common.d.ts +5 -0
  196. package/build/esm/shared/types/common.js +1 -0
  197. package/build/esm/shared/types/config.d.ts +49 -0
  198. package/build/esm/shared/types/config.js +1 -0
  199. package/build/esm/shared/types/index.d.ts +4 -0
  200. package/build/esm/shared/types/index.js +4 -0
  201. package/build/esm/shared/types/plugin.d.ts +8 -0
  202. package/build/esm/shared/types/plugin.js +1 -0
  203. package/build/esm/shared/types/state-and-params.d.ts +22 -0
  204. package/build/esm/shared/types/state-and-params.js +1 -0
  205. package/build/esm/shared/units/__tests__/state-and-params.test.d.ts +241 -0
  206. package/build/esm/shared/units/__tests__/state-and-params.test.js +295 -0
  207. package/build/esm/shared/units/datalens/index.d.ts +5 -0
  208. package/build/esm/shared/units/datalens/index.js +20 -0
  209. package/build/esm/shared/units/index.d.ts +1 -0
  210. package/build/esm/shared/units/index.js +1 -0
  211. package/build/esm/typings/common.d.ts +32 -0
  212. package/build/esm/typings/common.js +1 -0
  213. package/build/esm/typings/config.d.ts +7 -0
  214. package/build/esm/typings/config.js +1 -0
  215. package/build/esm/typings/global.d.ts +7 -0
  216. package/build/esm/typings/index.d.ts +3 -0
  217. package/build/esm/typings/index.js +3 -0
  218. package/build/esm/typings/plugin.d.ts +39 -0
  219. package/build/esm/typings/plugin.js +1 -0
  220. package/build/esm/utils/__tests__/mock.test.d.ts +1 -0
  221. package/build/esm/utils/__tests__/mock.test.js +8 -0
  222. package/build/esm/utils/configure.d.ts +9 -0
  223. package/build/esm/utils/configure.js +15 -0
  224. package/build/esm/utils/i18n.d.ts +7 -0
  225. package/build/esm/utils/i18n.js +9 -0
  226. package/build/esm/utils/index.d.ts +3 -0
  227. package/build/esm/utils/index.js +3 -0
  228. package/build/esm/utils/register-manager.d.ts +46 -0
  229. package/build/esm/utils/register-manager.js +54 -0
  230. package/build/esm/utils/update-manager.d.ts +37 -0
  231. package/build/esm/utils/update-manager.js +269 -0
  232. package/package.json +107 -0
@@ -0,0 +1,24 @@
1
+ .dashkit-plugin-title {
2
+ display: flex;
3
+ align-items: flex-start;
4
+ height: 100%;
5
+ font-weight: 500;
6
+ padding-bottom: 5px;
7
+ padding-right: 5px;
8
+ }
9
+ .dashkit-plugin-title_size_l {
10
+ font-size: 24px;
11
+ line-height: 28px;
12
+ }
13
+ .dashkit-plugin-title_size_m {
14
+ font-size: 20px;
15
+ line-height: 24px;
16
+ }
17
+ .dashkit-plugin-title_size_s {
18
+ font-size: var(--yc-text-body-3-font-size);
19
+ line-height: 24px;
20
+ }
21
+ .dashkit-plugin-title_size_xs {
22
+ font-size: 15px;
23
+ line-height: 20px;
24
+ }
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { PluginWidgetProps, Plugin } from '../../typings';
3
+ export interface PluginTitleProps extends PluginWidgetProps {
4
+ data: {
5
+ size: 'l' | 'm' | 's' | 'xs';
6
+ text: string;
7
+ showInTOC: boolean;
8
+ } & PluginWidgetProps['data'];
9
+ }
10
+ export declare class PluginTitle extends React.Component<PluginTitleProps> {
11
+ render(): JSX.Element;
12
+ }
13
+ declare const plugin: Plugin<PluginTitleProps>;
14
+ export default plugin;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PluginTitle = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const bem_cn_lite_1 = tslib_1.__importDefault(require("bem-cn-lite"));
7
+ const b = (0, bem_cn_lite_1.default)('dashkit-plugin-title');
8
+ class PluginTitle extends react_1.default.Component {
9
+ render() {
10
+ const { data } = this.props;
11
+ const text = data.text ? data.text : '';
12
+ const size = data.size ? data.size : false;
13
+ const id = data.showInTOC && text ? encodeURIComponent(text) : undefined;
14
+ return (react_1.default.createElement("div", { id: id, className: b({ size }) }, text));
15
+ }
16
+ }
17
+ exports.PluginTitle = PluginTitle;
18
+ const plugin = {
19
+ type: 'title',
20
+ defaultLayout: { w: 36, h: 2 },
21
+ renderer(props, forwardedRef) {
22
+ return react_1.default.createElement(PluginTitle, Object.assign({}, props, { ref: forwardedRef }));
23
+ },
24
+ };
25
+ exports.default = plugin;
@@ -0,0 +1,2 @@
1
+ export declare const CURRENT_VERSION = 2;
2
+ export declare const META_KEY = "__meta__";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.META_KEY = exports.CURRENT_VERSION = void 0;
4
+ exports.CURRENT_VERSION = 2;
5
+ exports.META_KEY = '__meta__';
@@ -0,0 +1 @@
1
+ export * from './common';
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./common"), exports);
@@ -0,0 +1,4 @@
1
+ export * from './constants';
2
+ export * from './types';
3
+ export * from './modules';
4
+ export * from './units';
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./constants"), exports);
5
+ tslib_1.__exportStar(require("./types"), exports);
6
+ tslib_1.__exportStar(require("./modules"), exports);
7
+ tslib_1.__exportStar(require("./units"), exports);
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const constants_1 = require("../../constants");
4
+ const helpers_1 = require("../helpers");
5
+ const DEFAULT_CONTROL_ID = 'controlId';
6
+ const DEFAULT_WIDGET_ID = 'widgetId';
7
+ const DEFAULT_WIDGET_TAB_ID = 'widget_tabId';
8
+ const NAMESPACE = 'default';
9
+ const getMockedControlItem = ({ id = DEFAULT_CONTROL_ID, defaults, }) => ({
10
+ id,
11
+ defaults,
12
+ data: {},
13
+ type: 'control',
14
+ namespace: NAMESPACE,
15
+ });
16
+ const getMockedWidgetItem = ({ id = DEFAULT_WIDGET_ID, tabs }) => ({
17
+ id,
18
+ data: { tabs },
19
+ type: 'widget',
20
+ namespace: NAMESPACE,
21
+ });
22
+ describe('modules.helpers', () => {
23
+ describe('formQueueData', () => {
24
+ it('return correct queue data for control: common', () => {
25
+ const itemsStateAndParams = {
26
+ [DEFAULT_CONTROL_ID]: {
27
+ params: {
28
+ scale: 'd',
29
+ view: 'normal',
30
+ },
31
+ },
32
+ [constants_1.META_KEY]: {
33
+ queue: [{ id: DEFAULT_CONTROL_ID }],
34
+ version: 2,
35
+ },
36
+ };
37
+ const controlItem1 = getMockedControlItem({ id: 'control-1' });
38
+ expect([]).toEqual((0, helpers_1.formQueueData)({ items: [controlItem1], itemsStateAndParams }));
39
+ const controlItem2 = getMockedControlItem({ id: 'control-2', defaults: { scale: 'm' } });
40
+ expect([]).toEqual((0, helpers_1.formQueueData)({ items: [controlItem2], itemsStateAndParams }));
41
+ const controlItem3 = getMockedControlItem({ defaults: { number: 'one', size: 's' } });
42
+ expect([
43
+ {
44
+ id: DEFAULT_CONTROL_ID,
45
+ namespace: NAMESPACE,
46
+ params: {},
47
+ },
48
+ ]).toEqual((0, helpers_1.formQueueData)({ items: [controlItem3], itemsStateAndParams }));
49
+ const controlItem4 = getMockedControlItem({ defaults: { scale: 'm', size: 's' } });
50
+ expect([
51
+ {
52
+ id: DEFAULT_CONTROL_ID,
53
+ namespace: NAMESPACE,
54
+ params: { scale: 'd' },
55
+ },
56
+ ]).toEqual((0, helpers_1.formQueueData)({ items: [controlItem4], itemsStateAndParams }));
57
+ const controlItem5 = getMockedControlItem({
58
+ defaults: { scale: 'm', size: 's', view: 'contrast' },
59
+ });
60
+ expect([
61
+ {
62
+ id: DEFAULT_CONTROL_ID,
63
+ namespace: NAMESPACE,
64
+ params: {
65
+ scale: 'd',
66
+ view: 'normal',
67
+ },
68
+ },
69
+ ]).toEqual((0, helpers_1.formQueueData)({ items: [controlItem5], itemsStateAndParams }));
70
+ });
71
+ it('return correct queue data for widget: common', () => {
72
+ const itemsStateAndParams = {
73
+ [DEFAULT_WIDGET_ID]: {
74
+ params: {
75
+ scale: 'd',
76
+ view: 'normal',
77
+ },
78
+ },
79
+ [constants_1.META_KEY]: {
80
+ queue: [{ id: DEFAULT_WIDGET_ID, tabId: DEFAULT_WIDGET_TAB_ID }],
81
+ version: 2,
82
+ },
83
+ };
84
+ const widgetItem1 = getMockedWidgetItem({ id: 'widget-1' });
85
+ expect([]).toEqual((0, helpers_1.formQueueData)({ items: [widgetItem1], itemsStateAndParams }));
86
+ const widgetItem2 = getMockedWidgetItem({
87
+ id: 'widget-2',
88
+ tabs: [{ id: DEFAULT_WIDGET_TAB_ID, params: { scale: 'm' } }],
89
+ });
90
+ expect([]).toEqual((0, helpers_1.formQueueData)({ items: [widgetItem2], itemsStateAndParams }));
91
+ const widgetItem3 = getMockedWidgetItem({
92
+ tabs: [{ id: 'widget-3-tabId', params: { scale: 'm' } }],
93
+ });
94
+ expect([]).toEqual((0, helpers_1.formQueueData)({ items: [widgetItem3], itemsStateAndParams }));
95
+ const widgetItem4 = getMockedWidgetItem({
96
+ tabs: [{ id: DEFAULT_WIDGET_TAB_ID }],
97
+ });
98
+ expect([
99
+ {
100
+ id: DEFAULT_WIDGET_ID,
101
+ namespace: NAMESPACE,
102
+ params: {},
103
+ },
104
+ ]).toEqual((0, helpers_1.formQueueData)({ items: [widgetItem4], itemsStateAndParams }));
105
+ const widgetItem5 = getMockedWidgetItem({
106
+ tabs: [{ id: DEFAULT_WIDGET_TAB_ID, params: { scale: 'm' } }],
107
+ });
108
+ expect([
109
+ {
110
+ id: DEFAULT_WIDGET_ID,
111
+ namespace: NAMESPACE,
112
+ params: { scale: 'd' },
113
+ },
114
+ ]).toEqual((0, helpers_1.formQueueData)({ items: [widgetItem5], itemsStateAndParams }));
115
+ });
116
+ it('return correct queue data for widget: check tabs', () => {
117
+ const TAB_ID = 'default_tab_id';
118
+ const itemsStateAndParams1 = {
119
+ [DEFAULT_WIDGET_ID]: {
120
+ params: { scale: 'd', view: 'normal' },
121
+ state: { tabId: DEFAULT_WIDGET_TAB_ID },
122
+ },
123
+ [constants_1.META_KEY]: {
124
+ queue: [{ id: DEFAULT_WIDGET_ID, tabId: DEFAULT_WIDGET_TAB_ID }],
125
+ version: 2,
126
+ },
127
+ };
128
+ const itemsStateAndParams2 = {
129
+ [DEFAULT_WIDGET_ID]: {
130
+ params: { scale: 'd', view: 'normal' },
131
+ state: { tabId: TAB_ID },
132
+ },
133
+ [constants_1.META_KEY]: {
134
+ queue: [{ id: DEFAULT_WIDGET_ID, tabId: TAB_ID }],
135
+ version: 2,
136
+ },
137
+ };
138
+ const itemsStateAndParams3 = {
139
+ [DEFAULT_WIDGET_ID]: {
140
+ params: { scale: 'd', view: 'normal' },
141
+ state: { tabId: 'anyTabId' },
142
+ },
143
+ [constants_1.META_KEY]: {
144
+ queue: [{ id: DEFAULT_WIDGET_ID, tabId: 'anyTabId' }],
145
+ version: 2,
146
+ },
147
+ };
148
+ const widgetItem = getMockedWidgetItem({
149
+ tabs: [
150
+ { id: DEFAULT_WIDGET_TAB_ID, params: { scale: 'm' } },
151
+ { id: TAB_ID, isDefault: true, params: { view: 'contrast' } },
152
+ ],
153
+ });
154
+ expect([
155
+ {
156
+ id: DEFAULT_WIDGET_ID,
157
+ namespace: NAMESPACE,
158
+ params: { scale: 'd' },
159
+ },
160
+ ]).toEqual((0, helpers_1.formQueueData)({ items: [widgetItem], itemsStateAndParams: itemsStateAndParams1 }));
161
+ expect([
162
+ {
163
+ id: DEFAULT_WIDGET_ID,
164
+ namespace: NAMESPACE,
165
+ params: { view: 'normal' },
166
+ },
167
+ ]).toEqual((0, helpers_1.formQueueData)({ items: [widgetItem], itemsStateAndParams: itemsStateAndParams2 }));
168
+ expect([]).toEqual((0, helpers_1.formQueueData)({ items: [widgetItem], itemsStateAndParams: itemsStateAndParams3 }));
169
+ });
170
+ it('return correct queue data for controls and widgets', () => {
171
+ const itemsStateAndParams = {
172
+ [DEFAULT_CONTROL_ID]: {
173
+ params: {
174
+ scale: 'd',
175
+ },
176
+ },
177
+ [DEFAULT_WIDGET_ID]: {
178
+ params: {
179
+ view: 'normal',
180
+ },
181
+ },
182
+ [constants_1.META_KEY]: {
183
+ queue: [
184
+ { id: DEFAULT_CONTROL_ID },
185
+ { id: DEFAULT_WIDGET_ID, tabId: DEFAULT_WIDGET_TAB_ID },
186
+ ],
187
+ version: 2,
188
+ },
189
+ };
190
+ const widgetItem1 = getMockedWidgetItem({ id: 'widget-1' });
191
+ const widgetItem2 = getMockedWidgetItem({
192
+ id: 'widget-2',
193
+ tabs: [{ id: 'widget-2-tabId', params: { view: 'contrast' } }],
194
+ });
195
+ const widgetItem3 = getMockedWidgetItem({
196
+ tabs: [{ id: DEFAULT_WIDGET_TAB_ID, params: { view: 'contrast' } }],
197
+ });
198
+ const control1 = getMockedControlItem({ id: 'control-1' });
199
+ const control2 = getMockedControlItem({ defaults: { scale: 'm', view: 'contrast' } });
200
+ expect([
201
+ {
202
+ id: DEFAULT_CONTROL_ID,
203
+ namespace: NAMESPACE,
204
+ params: { scale: 'd' },
205
+ },
206
+ {
207
+ id: DEFAULT_WIDGET_ID,
208
+ namespace: NAMESPACE,
209
+ params: { view: 'normal' },
210
+ },
211
+ ]).toEqual((0, helpers_1.formQueueData)({
212
+ items: [widgetItem2, widgetItem3, control1, widgetItem1, control2],
213
+ itemsStateAndParams,
214
+ }));
215
+ });
216
+ });
217
+ });
@@ -0,0 +1,42 @@
1
+ import { PluginBase, ConfigItem, ItemsStateAndParams, StateAndParamsMetaData, StringParams, ConfigConnection, ConfigAliases, ConfigItemWithTabs, Config } from '../types';
2
+ export declare function prerenderItems({ items, plugins, }: {
3
+ items: ConfigItem[];
4
+ plugins: PluginBase[];
5
+ }): ConfigItem[];
6
+ export declare function getItemsStateAndParamsMeta(itemsStateAndParams: ItemsStateAndParams): StateAndParamsMetaData | undefined;
7
+ export declare function getCurrentVersion(itemsStateAndParams: ItemsStateAndParams): number;
8
+ export declare function isItemWithTabs(item: Pick<ConfigItem, 'data'>): item is Pick<ConfigItemWithTabs, 'data'>;
9
+ export declare type FormedQueueData = {
10
+ id: string;
11
+ namespace: string;
12
+ params: StringParams;
13
+ };
14
+ export declare function formQueueData({ items, itemsStateAndParams, }: {
15
+ items: ConfigItem[];
16
+ itemsStateAndParams: ItemsStateAndParams;
17
+ }): FormedQueueData[];
18
+ export declare function resolveItemInnerId({ item, itemsStateAndParams, }: {
19
+ item: ConfigItem;
20
+ itemsStateAndParams: ItemsStateAndParams;
21
+ }): string;
22
+ export declare function getMapItemsIgnores({ items, ignores, itemsStateAndParams, isFirstVersion, }: {
23
+ items: ConfigItem[];
24
+ ignores: ConfigConnection[];
25
+ itemsStateAndParams: ItemsStateAndParams;
26
+ isFirstVersion: boolean;
27
+ }): Record<string, string[]>;
28
+ export declare function mergeParamsWithAliases({ aliases, namespace, params, }: {
29
+ aliases: ConfigAliases;
30
+ namespace: string;
31
+ params: StringParams;
32
+ }): StringParams;
33
+ export declare function getInitialItemsStateAndParamsMeta(): StateAndParamsMetaData;
34
+ interface ChangeQueueArg {
35
+ id: string;
36
+ tabId?: string;
37
+ config: Config;
38
+ itemsStateAndParams: ItemsStateAndParams;
39
+ }
40
+ export declare function addToQueue({ id, tabId, config, itemsStateAndParams, }: ChangeQueueArg): StateAndParamsMetaData;
41
+ export declare function deleteFromQueue(data: ChangeQueueArg): StateAndParamsMetaData;
42
+ export {};
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deleteFromQueue = exports.addToQueue = exports.getInitialItemsStateAndParamsMeta = exports.mergeParamsWithAliases = exports.getMapItemsIgnores = exports.resolveItemInnerId = exports.formQueueData = exports.isItemWithTabs = exports.getCurrentVersion = exports.getItemsStateAndParamsMeta = exports.prerenderItems = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const keyBy_1 = tslib_1.__importDefault(require("lodash/keyBy"));
6
+ const get_1 = tslib_1.__importDefault(require("lodash/get"));
7
+ const invert_1 = tslib_1.__importDefault(require("lodash/invert"));
8
+ const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
9
+ const pick_1 = tslib_1.__importDefault(require("lodash/pick"));
10
+ const constants_1 = require("../constants");
11
+ function getNormalizedPlugins(plugins) {
12
+ return (0, keyBy_1.default)(plugins, 'type');
13
+ }
14
+ function prerenderItems({ items, plugins, }) {
15
+ const normalizedPlugins = getNormalizedPlugins(plugins);
16
+ return items.map((item) => {
17
+ const { type } = item;
18
+ const plugin = normalizedPlugins[type];
19
+ return typeof plugin.prerenderMiddleware === 'function'
20
+ ? plugin.prerenderMiddleware(item)
21
+ : item;
22
+ });
23
+ }
24
+ exports.prerenderItems = prerenderItems;
25
+ function getItemsStateAndParamsMeta(itemsStateAndParams) {
26
+ const meta = itemsStateAndParams === null || itemsStateAndParams === void 0 ? void 0 : itemsStateAndParams[constants_1.META_KEY];
27
+ return meta;
28
+ }
29
+ exports.getItemsStateAndParamsMeta = getItemsStateAndParamsMeta;
30
+ function getCurrentVersion(itemsStateAndParams) {
31
+ if ((0, isEmpty_1.default)(itemsStateAndParams)) {
32
+ return constants_1.CURRENT_VERSION;
33
+ }
34
+ const meta = getItemsStateAndParamsMeta(itemsStateAndParams);
35
+ if (!meta) {
36
+ const withParams = Object.keys(itemsStateAndParams).some((id) => {
37
+ return Boolean(itemsStateAndParams[id].params);
38
+ });
39
+ if (withParams) {
40
+ return 1;
41
+ }
42
+ return constants_1.CURRENT_VERSION;
43
+ }
44
+ return meta.version;
45
+ }
46
+ exports.getCurrentVersion = getCurrentVersion;
47
+ function nonNullable(value) {
48
+ return value !== null && value !== undefined;
49
+ }
50
+ function isItemWithTabs(item) {
51
+ var _a;
52
+ return Array.isArray((_a = item === null || item === void 0 ? void 0 : item.data) === null || _a === void 0 ? void 0 : _a.tabs);
53
+ }
54
+ exports.isItemWithTabs = isItemWithTabs;
55
+ // Массив параметров, которые исходят от виджетов, согласно очереди
56
+ function formQueueData({ items, itemsStateAndParams, }) {
57
+ var _a;
58
+ const queue = ((_a = getItemsStateAndParamsMeta(itemsStateAndParams)) === null || _a === void 0 ? void 0 : _a.queue) || [];
59
+ const keyById = (0, keyBy_1.default)(items, 'id');
60
+ return queue
61
+ .map((queueItem) => {
62
+ var _a;
63
+ const { id: queueId, tabId } = queueItem;
64
+ const item = keyById[queueId];
65
+ if (!item) {
66
+ return null;
67
+ }
68
+ let itemDefaultParams;
69
+ if (isItemWithTabs(item)) {
70
+ if (!tabId || resolveItemInnerId({ item, itemsStateAndParams }) !== tabId) {
71
+ return null;
72
+ }
73
+ itemDefaultParams =
74
+ ((_a = item.data.tabs.find((tabData) => tabData.id === tabId)) === null || _a === void 0 ? void 0 : _a.params) || {};
75
+ }
76
+ else {
77
+ itemDefaultParams = item.defaults || {};
78
+ }
79
+ const itemQueueParams = (0, get_1.default)(itemsStateAndParams, [item.id, 'params'], {});
80
+ return {
81
+ id: item.id,
82
+ namespace: item.namespace,
83
+ params: (0, pick_1.default)(itemQueueParams, Object.keys(itemDefaultParams)),
84
+ };
85
+ })
86
+ .filter(nonNullable);
87
+ }
88
+ exports.formQueueData = formQueueData;
89
+ function resolveItemInnerId({ item, itemsStateAndParams, }) {
90
+ var _a, _b;
91
+ const { id } = item;
92
+ const stateTabId = (_b = (_a = itemsStateAndParams[id]) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.tabId;
93
+ const { tabs } = item.data;
94
+ if (stateTabId && tabs.some((tab) => tab.id === stateTabId)) {
95
+ return stateTabId;
96
+ }
97
+ const indexIsDefault = tabs.findIndex(({ isDefault }) => isDefault);
98
+ return indexIsDefault === -1 ? tabs[0].id : tabs[indexIsDefault].id;
99
+ }
100
+ exports.resolveItemInnerId = resolveItemInnerId;
101
+ // В config.connections в from/to может быть как id item'a (item.id), так и id таба (item.data.tabs[].id)
102
+ // Тут мы нормализуем к виду Record<itemId: ignoredItemId[]>
103
+ function getMapItemsIgnores({ items, ignores, itemsStateAndParams, isFirstVersion, }) {
104
+ // Record<itemId, innerId (tabId | itemId)>
105
+ const mapIds = items.reduce((acc, item) => {
106
+ return Object.assign(Object.assign({}, acc), { [item.id]: isItemWithTabs(item)
107
+ ? resolveItemInnerId({ item, itemsStateAndParams })
108
+ : item.id });
109
+ }, {});
110
+ // Record<innerId (tabId | itemId), itemId>
111
+ const invertedMapIds = (0, invert_1.default)(mapIds);
112
+ return items.reduce((acc, item) => {
113
+ return Object.assign(Object.assign({}, acc), { [item.id]: ignores
114
+ .filter(({ from, to }) => {
115
+ if (isFirstVersion) {
116
+ // В первой версии был баг - если есть игнор на один таб, то весь виджет игнорит селектор.
117
+ // Повторяем это неправильное поведение,
118
+ // иначе будут прилетать дефолты селекта в табы, которые не игнорят.
119
+ const fromInTabs = isItemWithTabs(item) && item.data.tabs.some(({ id }) => id === from);
120
+ return (from === item.id || fromInTabs) && invertedMapIds[to];
121
+ }
122
+ return from === mapIds[item.id] && invertedMapIds[to];
123
+ })
124
+ .map(({ to }) => invertedMapIds[to]) });
125
+ }, {});
126
+ }
127
+ exports.getMapItemsIgnores = getMapItemsIgnores;
128
+ function mergeParamsWithAliases({ aliases, namespace, params, }) {
129
+ const aliasesByNamespace = (0, get_1.default)(aliases, [namespace], []);
130
+ return Object.keys(params).reduce((matchedParams, paramKey) => {
131
+ const paramValue = params[paramKey];
132
+ const collectAliasesParamsKeys = aliasesByNamespace.reduce((collect, group) => {
133
+ return group.includes(paramKey) ? collect.concat(group) : collect;
134
+ }, [paramKey]);
135
+ return Object.assign(Object.assign({}, matchedParams), collectAliasesParamsKeys.reduce((acc, matchedKey) => {
136
+ return Object.assign(Object.assign({}, acc), { [matchedKey]: paramValue });
137
+ }, {}));
138
+ }, {});
139
+ }
140
+ exports.mergeParamsWithAliases = mergeParamsWithAliases;
141
+ function getInitialItemsStateAndParamsMeta() {
142
+ return {
143
+ queue: [],
144
+ version: constants_1.CURRENT_VERSION,
145
+ };
146
+ }
147
+ exports.getInitialItemsStateAndParamsMeta = getInitialItemsStateAndParamsMeta;
148
+ function addToQueue({ id, tabId, config, itemsStateAndParams, }) {
149
+ const queueItem = { id };
150
+ if (tabId) {
151
+ queueItem.tabId = tabId;
152
+ }
153
+ const meta = getItemsStateAndParamsMeta(itemsStateAndParams);
154
+ if (!meta) {
155
+ return { queue: [queueItem], version: constants_1.CURRENT_VERSION };
156
+ }
157
+ const { items } = config;
158
+ const actualIds = items.map((item) => item.id);
159
+ const metaQueue = meta.queue || [];
160
+ return {
161
+ queue: metaQueue
162
+ .filter((item) => actualIds.includes(item.id) && item.id !== id)
163
+ .concat(queueItem),
164
+ version: meta.version || constants_1.CURRENT_VERSION,
165
+ };
166
+ }
167
+ exports.addToQueue = addToQueue;
168
+ function deleteFromQueue(data) {
169
+ const meta = addToQueue(data);
170
+ return Object.assign(Object.assign({}, meta), { queue: meta.queue.slice(0, -1) });
171
+ }
172
+ exports.deleteFromQueue = deleteFromQueue;
@@ -0,0 +1,2 @@
1
+ export * from './helpers';
2
+ export * from './state-and-params';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./helpers"), exports);
5
+ tslib_1.__exportStar(require("./state-and-params"), exports);
@@ -0,0 +1,16 @@
1
+ import { GlobalParams, Config, ItemsStateAndParams, PluginBase, StringParams, ItemState } from '../types';
2
+ export interface GetItemsParamsArg {
3
+ defaultGlobalParams: GlobalParams;
4
+ globalParams: GlobalParams;
5
+ config: Config;
6
+ itemsStateAndParams: ItemsStateAndParams;
7
+ plugins: PluginBase[];
8
+ }
9
+ declare type GetItemsParamsReturn = Record<string, StringParams>;
10
+ export declare function getItemsParams({ defaultGlobalParams, globalParams, config, itemsStateAndParams, plugins, }: GetItemsParamsArg): GetItemsParamsReturn;
11
+ export declare function getItemsState({ config, itemsStateAndParams, }: {
12
+ config: Config;
13
+ itemsStateAndParams: ItemsStateAndParams;
14
+ }): Record<string, ItemState>;
15
+ export declare function getItemsStateAndParams({ defaultGlobalParams, globalParams, config, itemsStateAndParams, plugins, }: GetItemsParamsArg): ItemsStateAndParams;
16
+ export {};
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getItemsStateAndParams = exports.getItemsState = exports.getItemsParams = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const groupBy_1 = tslib_1.__importDefault(require("lodash/groupBy"));
6
+ const helpers_1 = require("./helpers");
7
+ const constants_1 = require("../constants");
8
+ function getItemsParams({ defaultGlobalParams = {}, globalParams = {}, config, itemsStateAndParams, plugins, }) {
9
+ const { aliases, connections } = config;
10
+ const items = (0, helpers_1.prerenderItems)({ items: config.items, plugins });
11
+ const isFirstVersion = (0, helpers_1.getCurrentVersion)(itemsStateAndParams) === 1;
12
+ const queueData = isFirstVersion
13
+ ? []
14
+ : (0, helpers_1.formQueueData)({ items, itemsStateAndParams });
15
+ // В будущем учитывать не только игноры, когда такой kind появится
16
+ const mapItemsIgnores = (0, helpers_1.getMapItemsIgnores)({
17
+ items,
18
+ ignores: connections.filter(({ kind }) => kind === 'ignore'),
19
+ itemsStateAndParams,
20
+ isFirstVersion,
21
+ });
22
+ const groupByNamespace = (0, groupBy_1.default)(items, 'namespace');
23
+ const itemsWithDefaultsByNamespace = Object.keys(groupByNamespace).reduce((acc, namespace) => {
24
+ return Object.assign(Object.assign({}, acc), {
25
+ // Сейчас дефолты только у Селектов, затем для виджетов нужно доставать из item.data.tabs[].defaults
26
+ // но определиться с порядком их применения
27
+ [namespace]: groupByNamespace[namespace].filter((item) => item.defaults) });
28
+ }, {});
29
+ return items.reduce((itemsParams, item) => {
30
+ var _a;
31
+ const { id, namespace } = item;
32
+ const getMergedParams = (params) => (0, helpers_1.mergeParamsWithAliases)({ aliases, namespace, params: params || {} });
33
+ const itemIgnores = mapItemsIgnores[id];
34
+ const affectingItemsWithDefaults = itemsWithDefaultsByNamespace[namespace].filter((itemWithDefaults) => !itemIgnores.includes(itemWithDefaults.id));
35
+ let itemParams = Object.assign({}, getMergedParams(defaultGlobalParams),
36
+ // Стартовые дефолтные параметры
37
+ affectingItemsWithDefaults.reduceRight((defaultParams, itemWithDefaults) => {
38
+ return Object.assign(Object.assign({}, defaultParams), getMergedParams(itemWithDefaults.defaults || {}));
39
+ }, {}), getMergedParams(globalParams));
40
+ if (isFirstVersion) {
41
+ itemParams = Object.assign(itemParams, ((_a = itemsStateAndParams === null || itemsStateAndParams === void 0 ? void 0 : itemsStateAndParams[id]) === null || _a === void 0 ? void 0 : _a.params) || {});
42
+ }
43
+ else {
44
+ itemParams = Object.assign(itemParams,
45
+ // Параметры согласно очереди применения параметров
46
+ queueData.reduce((queueParams, data) => {
47
+ if (data.namespace !== namespace || itemIgnores.includes(data.id)) {
48
+ return queueParams;
49
+ }
50
+ return Object.assign(Object.assign({}, queueParams), getMergedParams(data.params));
51
+ }, {}));
52
+ }
53
+ return Object.assign(Object.assign({}, itemsParams), { [id]: itemParams });
54
+ }, {});
55
+ }
56
+ exports.getItemsParams = getItemsParams;
57
+ function getItemsState({ config, itemsStateAndParams, }) {
58
+ return config.items.reduce((acc, { id }) => {
59
+ var _a;
60
+ acc[id] = ((_a = itemsStateAndParams === null || itemsStateAndParams === void 0 ? void 0 : itemsStateAndParams[id]) === null || _a === void 0 ? void 0 : _a.state) || {};
61
+ return acc;
62
+ }, {});
63
+ }
64
+ exports.getItemsState = getItemsState;
65
+ function getItemsStateAndParams({ defaultGlobalParams = {}, globalParams = {}, config, itemsStateAndParams, plugins, }) {
66
+ const params = getItemsParams({
67
+ defaultGlobalParams,
68
+ globalParams,
69
+ config,
70
+ itemsStateAndParams,
71
+ plugins,
72
+ });
73
+ const state = getItemsState({ config, itemsStateAndParams });
74
+ const uniqIds = new Set([...Object.keys(params), ...Object.keys(state)]);
75
+ const result = Array.from(uniqIds).reduce((acc, id) => {
76
+ const data = {};
77
+ if (id in params) {
78
+ data.params = params[id];
79
+ }
80
+ if (id in state) {
81
+ data.state = state[id];
82
+ }
83
+ return Object.assign(Object.assign({}, acc), { [id]: data });
84
+ }, {});
85
+ const version = (0, helpers_1.getCurrentVersion)(itemsStateAndParams);
86
+ if (version === 1) {
87
+ return result;
88
+ }
89
+ const meta = {
90
+ [constants_1.META_KEY]: itemsStateAndParams[constants_1.META_KEY],
91
+ };
92
+ return Object.assign(Object.assign({}, meta), result);
93
+ }
94
+ exports.getItemsStateAndParams = getItemsStateAndParams;
@@ -0,0 +1,5 @@
1
+ export declare type Dictionary<T = unknown> = Record<string, T>;
2
+ export interface StringParams extends Dictionary<string | string[]> {
3
+ }
4
+ export interface GlobalParams extends StringParams {
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });