@doyourjob/gravity-ui-page-constructor 5.31.21 → 5.31.22

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.
@@ -22,14 +22,6 @@ unpredictable css rules order in build */
22
22
  line-height: var(--g-text-display-1-line-height, var(--pc-text-display-1-line-height));
23
23
  }
24
24
  }
25
- .pc-highlight-table-block__content {
26
- padding: 0 8px;
27
- }
28
- @media (max-width: 769px) {
29
- .pc-highlight-table-block__content {
30
- min-width: 1024px;
31
- }
32
- }
33
25
  .pc-highlight-table-block__table {
34
26
  overflow: auto;
35
27
  }
@@ -44,6 +36,9 @@ unpredictable css rules order in build */
44
36
  display: none;
45
37
  }
46
38
  }
39
+ .pc-highlight-table-block__content {
40
+ width: max-content;
41
+ }
47
42
  .pc-highlight-table-block__head {
48
43
  color: rgba(0, 0, 0, 0.5);
49
44
  }
@@ -52,19 +47,19 @@ unpredictable css rules order in build */
52
47
  }
53
48
  .pc-highlight-table-block__head, .pc-highlight-table-block__body {
54
49
  border-radius: 10px;
55
- padding: 0 20px;
56
- margin: 0 -8px;
57
50
  overflow: hidden;
58
51
  }
59
- .pc-highlight-table-block__row.pc-highlight-table-block__row.pc-highlight-table-block__row.pc-highlight-table-block__row {
60
- margin-left: -20px;
61
- margin-right: -20px;
52
+ .pc-highlight-table-block__row {
53
+ display: flex;
62
54
  padding: 12px;
63
55
  }
64
-
65
56
  .pc-highlight-table-block__row + .pc-highlight-table-block__row {
66
57
  border-top: 1px solid var(--g-color-private-black-100);
67
58
  }
59
+ .pc-highlight-table-block__cell {
60
+ padding-right: 8px;
61
+ padding-left: 8px;
62
+ }
68
63
  .pc-highlight-table-block__cell p {
69
64
  margin: 0;
70
65
  }
@@ -4,35 +4,42 @@ exports.HighlightTableBlock = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const react_1 = tslib_1.__importStar(require("react"));
6
6
  const uikit_1 = require("@gravity-ui/uikit");
7
+ const debounce_1 = tslib_1.__importDefault(require("lodash/debounce"));
7
8
  const components_1 = require("../../components");
8
- const grid_1 = require("../../grid");
9
9
  const utils_1 = require("../../utils");
10
10
  const b = (0, utils_1.block)('highlight-table-block');
11
- function getColSize(value) {
12
- switch (value) {
13
- case 'xxl':
14
- return 12;
15
- case 'xl':
16
- return 6;
17
- case 'l':
18
- return 4;
19
- case 'm':
20
- return 3;
21
- case 's':
22
- return 2;
23
- case 'xs':
24
- return 1;
25
- default:
26
- return undefined;
27
- }
28
- }
29
11
  const HighlightTableBlock = (props) => {
30
12
  const { title, description, table } = props;
31
13
  const firstRow = table.content[0] || [];
32
14
  const otherRows = table.content.slice(1);
15
+ const customColumnWidth = table.customColumnWidth || [];
16
+ const maxContentColumns = Math.max(...table.content.map((row) => row.length));
17
+ const maxCustomColumn = customColumnWidth.reduce((val, value) => val + value, 0) || 0;
18
+ const maxColumns = maxContentColumns > maxCustomColumn
19
+ ? maxCustomColumn + (maxContentColumns - customColumnWidth.length) * 2
20
+ : maxCustomColumn;
21
+ const blockRef = (0, react_1.useRef)(null);
33
22
  const tableRef = (0, react_1.useRef)(null);
23
+ const tableContentRef = (0, react_1.useRef)(null);
34
24
  const scrollBarRef = (0, react_1.useRef)(null);
35
25
  const scrollThumbRef = (0, react_1.useRef)(null);
26
+ (0, react_1.useEffect)(() => {
27
+ const blockElem = blockRef.current;
28
+ const tableContentElem = tableContentRef.current;
29
+ if (!tableContentElem || !blockElem)
30
+ return () => { };
31
+ const updateSizes = (0, debounce_1.default)(() => {
32
+ const width = Math.max(672, blockElem.clientWidth);
33
+ const tableWidth = (1 / (12 / maxColumns)) * width;
34
+ tableContentElem.style.setProperty('width', `${tableWidth}px`);
35
+ tableContentElem.style.setProperty('--block-width', `${width}px`);
36
+ });
37
+ updateSizes();
38
+ blockElem.addEventListener('resize', updateSizes);
39
+ return () => {
40
+ blockElem.removeEventListener('resize', updateSizes);
41
+ };
42
+ }, [maxColumns]);
36
43
  (0, react_1.useEffect)(() => {
37
44
  const tableElem = tableRef.current;
38
45
  const scrollBar = scrollBarRef.current;
@@ -45,7 +52,7 @@ const HighlightTableBlock = (props) => {
45
52
  scrollThumb.style.setProperty('transform', `translateX(${scrollLeft}px)`);
46
53
  scrollThumb.style.setProperty('width', `${scrollWidth}px`);
47
54
  };
48
- updateProgress();
55
+ setTimeout(updateProgress, 0);
49
56
  tableElem.addEventListener('scroll', updateProgress);
50
57
  return () => {
51
58
  tableElem.removeEventListener('scroll', updateProgress);
@@ -53,18 +60,21 @@ const HighlightTableBlock = (props) => {
53
60
  }, []);
54
61
  const renderRow = (0, react_1.useCallback)((row, index) => {
55
62
  var _a, _b;
56
- return (react_1.default.createElement(grid_1.Row, { key: index, className: b('row'), style: { backgroundColor: (_b = (_a = table.highlighter) === null || _a === void 0 ? void 0 : _a[index]) !== null && _b !== void 0 ? _b : '' } }, row.map((cell, cellIndex) => {
63
+ return (react_1.default.createElement("div", { key: index, className: b('row'), style: { backgroundColor: (_b = (_a = table.highlighter) === null || _a === void 0 ? void 0 : _a[index]) !== null && _b !== void 0 ? _b : '' } }, row.map((cell, cellIndex) => {
57
64
  var _a, _b, _c;
58
- return (react_1.default.createElement(grid_1.Col, { sizes: getColSize((_a = table.customColumnWidth) === null || _a === void 0 ? void 0 : _a[cellIndex]), key: cellIndex, className: b('cell'), style: { textAlign: (_c = (_b = table.justify) === null || _b === void 0 ? void 0 : _b[cellIndex]) !== null && _c !== void 0 ? _c : 'left' } },
65
+ return (react_1.default.createElement("div", { key: cellIndex, className: b('cell'), style: {
66
+ textAlign: (_b = (_a = table.justify) === null || _a === void 0 ? void 0 : _a[cellIndex]) !== null && _b !== void 0 ? _b : 'left',
67
+ width: `calc(var(--block-width) * ${1 / (12 / (((_c = table.customColumnWidth) === null || _c === void 0 ? void 0 : _c[cellIndex]) || 2))})`,
68
+ } },
59
69
  react_1.default.createElement(components_1.HTML, null, cell)));
60
70
  })));
61
71
  }, [table.customColumnWidth, table.highlighter, table.justify]);
62
- return (react_1.default.createElement("div", { className: b() },
72
+ return (react_1.default.createElement("div", { ref: blockRef, className: b() },
63
73
  react_1.default.createElement(uikit_1.Text, { className: b('title'), variant: "header-2" }, title),
64
74
  description && (react_1.default.createElement("div", { className: b('description') },
65
75
  react_1.default.createElement(components_1.YFMWrapper, { content: description, modifiers: { constructor: true } }))),
66
76
  react_1.default.createElement("div", { ref: tableRef, className: b('table') },
67
- react_1.default.createElement(grid_1.Grid, { className: b('content') },
77
+ react_1.default.createElement("div", { ref: tableContentRef, className: b('content') },
68
78
  react_1.default.createElement("div", { className: b('head') }, renderRow(firstRow, 0)),
69
79
  react_1.default.createElement("div", { className: b('body') }, otherRows.map(renderRow)))),
70
80
  react_1.default.createElement("div", { ref: scrollBarRef, className: b('scrollbar') },
@@ -39,7 +39,7 @@ export declare const HighlightTableBlock: {
39
39
  type: string;
40
40
  items: {
41
41
  type: string;
42
- enum: string[];
42
+ enum: number[];
43
43
  };
44
44
  };
45
45
  type: {};
@@ -36,7 +36,7 @@ exports.HighlightTableBlock = {
36
36
  type: 'array',
37
37
  items: {
38
38
  type: 'string',
39
- enum: ['xxl', 'xl', 'l', 'm', 's', 'xs'],
39
+ enum: [12, 6, 4, 3, 2],
40
40
  },
41
41
  } }),
42
42
  } }),
@@ -267,7 +267,7 @@ export interface TableBlockProps {
267
267
  }
268
268
  export interface HighlightTableData {
269
269
  content: string[][];
270
- customColumnWidth?: ('xxl' | 'xl' | 'l' | 'm' | 's' | 'xs')[];
270
+ customColumnWidth?: (12 | 6 | 4 | 3 | 2)[];
271
271
  justify?: ('left' | 'right' | 'center')[];
272
272
  highlighter?: string[];
273
273
  }
@@ -22,14 +22,6 @@ unpredictable css rules order in build */
22
22
  line-height: var(--g-text-display-1-line-height, var(--pc-text-display-1-line-height));
23
23
  }
24
24
  }
25
- .pc-highlight-table-block__content {
26
- padding: 0 8px;
27
- }
28
- @media (max-width: 769px) {
29
- .pc-highlight-table-block__content {
30
- min-width: 1024px;
31
- }
32
- }
33
25
  .pc-highlight-table-block__table {
34
26
  overflow: auto;
35
27
  }
@@ -44,6 +36,9 @@ unpredictable css rules order in build */
44
36
  display: none;
45
37
  }
46
38
  }
39
+ .pc-highlight-table-block__content {
40
+ width: max-content;
41
+ }
47
42
  .pc-highlight-table-block__head {
48
43
  color: rgba(0, 0, 0, 0.5);
49
44
  }
@@ -52,19 +47,19 @@ unpredictable css rules order in build */
52
47
  }
53
48
  .pc-highlight-table-block__head, .pc-highlight-table-block__body {
54
49
  border-radius: 10px;
55
- padding: 0 20px;
56
- margin: 0 -8px;
57
50
  overflow: hidden;
58
51
  }
59
- .pc-highlight-table-block__row.pc-highlight-table-block__row.pc-highlight-table-block__row.pc-highlight-table-block__row {
60
- margin-left: -20px;
61
- margin-right: -20px;
52
+ .pc-highlight-table-block__row {
53
+ display: flex;
62
54
  padding: 12px;
63
55
  }
64
-
65
56
  .pc-highlight-table-block__row + .pc-highlight-table-block__row {
66
57
  border-top: 1px solid var(--g-color-private-black-100);
67
58
  }
59
+ .pc-highlight-table-block__cell {
60
+ padding-right: 8px;
61
+ padding-left: 8px;
62
+ }
68
63
  .pc-highlight-table-block__cell p {
69
64
  margin: 0;
70
65
  }
@@ -1,35 +1,42 @@
1
1
  import React, { useCallback, useEffect, useRef } from 'react';
2
2
  import { Text } from '@gravity-ui/uikit';
3
+ import debounce from 'lodash/debounce';
3
4
  import { HTML, YFMWrapper } from '../../components';
4
- import { Col, Grid, Row } from '../../grid';
5
5
  import { block } from '../../utils';
6
6
  import './HighlightTable.css';
7
7
  const b = block('highlight-table-block');
8
- function getColSize(value) {
9
- switch (value) {
10
- case 'xxl':
11
- return 12;
12
- case 'xl':
13
- return 6;
14
- case 'l':
15
- return 4;
16
- case 'm':
17
- return 3;
18
- case 's':
19
- return 2;
20
- case 'xs':
21
- return 1;
22
- default:
23
- return undefined;
24
- }
25
- }
26
8
  export const HighlightTableBlock = (props) => {
27
9
  const { title, description, table } = props;
28
10
  const firstRow = table.content[0] || [];
29
11
  const otherRows = table.content.slice(1);
12
+ const customColumnWidth = table.customColumnWidth || [];
13
+ const maxContentColumns = Math.max(...table.content.map((row) => row.length));
14
+ const maxCustomColumn = customColumnWidth.reduce((val, value) => val + value, 0) || 0;
15
+ const maxColumns = maxContentColumns > maxCustomColumn
16
+ ? maxCustomColumn + (maxContentColumns - customColumnWidth.length) * 2
17
+ : maxCustomColumn;
18
+ const blockRef = useRef(null);
30
19
  const tableRef = useRef(null);
20
+ const tableContentRef = useRef(null);
31
21
  const scrollBarRef = useRef(null);
32
22
  const scrollThumbRef = useRef(null);
23
+ useEffect(() => {
24
+ const blockElem = blockRef.current;
25
+ const tableContentElem = tableContentRef.current;
26
+ if (!tableContentElem || !blockElem)
27
+ return () => { };
28
+ const updateSizes = debounce(() => {
29
+ const width = Math.max(672, blockElem.clientWidth);
30
+ const tableWidth = (1 / (12 / maxColumns)) * width;
31
+ tableContentElem.style.setProperty('width', `${tableWidth}px`);
32
+ tableContentElem.style.setProperty('--block-width', `${width}px`);
33
+ });
34
+ updateSizes();
35
+ blockElem.addEventListener('resize', updateSizes);
36
+ return () => {
37
+ blockElem.removeEventListener('resize', updateSizes);
38
+ };
39
+ }, [maxColumns]);
33
40
  useEffect(() => {
34
41
  const tableElem = tableRef.current;
35
42
  const scrollBar = scrollBarRef.current;
@@ -42,7 +49,7 @@ export const HighlightTableBlock = (props) => {
42
49
  scrollThumb.style.setProperty('transform', `translateX(${scrollLeft}px)`);
43
50
  scrollThumb.style.setProperty('width', `${scrollWidth}px`);
44
51
  };
45
- updateProgress();
52
+ setTimeout(updateProgress, 0);
46
53
  tableElem.addEventListener('scroll', updateProgress);
47
54
  return () => {
48
55
  tableElem.removeEventListener('scroll', updateProgress);
@@ -50,18 +57,21 @@ export const HighlightTableBlock = (props) => {
50
57
  }, []);
51
58
  const renderRow = useCallback((row, index) => {
52
59
  var _a, _b;
53
- return (React.createElement(Row, { key: index, className: b('row'), style: { backgroundColor: (_b = (_a = table.highlighter) === null || _a === void 0 ? void 0 : _a[index]) !== null && _b !== void 0 ? _b : '' } }, row.map((cell, cellIndex) => {
60
+ return (React.createElement("div", { key: index, className: b('row'), style: { backgroundColor: (_b = (_a = table.highlighter) === null || _a === void 0 ? void 0 : _a[index]) !== null && _b !== void 0 ? _b : '' } }, row.map((cell, cellIndex) => {
54
61
  var _a, _b, _c;
55
- return (React.createElement(Col, { sizes: getColSize((_a = table.customColumnWidth) === null || _a === void 0 ? void 0 : _a[cellIndex]), key: cellIndex, className: b('cell'), style: { textAlign: (_c = (_b = table.justify) === null || _b === void 0 ? void 0 : _b[cellIndex]) !== null && _c !== void 0 ? _c : 'left' } },
62
+ return (React.createElement("div", { key: cellIndex, className: b('cell'), style: {
63
+ textAlign: (_b = (_a = table.justify) === null || _a === void 0 ? void 0 : _a[cellIndex]) !== null && _b !== void 0 ? _b : 'left',
64
+ width: `calc(var(--block-width) * ${1 / (12 / (((_c = table.customColumnWidth) === null || _c === void 0 ? void 0 : _c[cellIndex]) || 2))})`,
65
+ } },
56
66
  React.createElement(HTML, null, cell)));
57
67
  })));
58
68
  }, [table.customColumnWidth, table.highlighter, table.justify]);
59
- return (React.createElement("div", { className: b() },
69
+ return (React.createElement("div", { ref: blockRef, className: b() },
60
70
  React.createElement(Text, { className: b('title'), variant: "header-2" }, title),
61
71
  description && (React.createElement("div", { className: b('description') },
62
72
  React.createElement(YFMWrapper, { content: description, modifiers: { constructor: true } }))),
63
73
  React.createElement("div", { ref: tableRef, className: b('table') },
64
- React.createElement(Grid, { className: b('content') },
74
+ React.createElement("div", { ref: tableContentRef, className: b('content') },
65
75
  React.createElement("div", { className: b('head') }, renderRow(firstRow, 0)),
66
76
  React.createElement("div", { className: b('body') }, otherRows.map(renderRow)))),
67
77
  React.createElement("div", { ref: scrollBarRef, className: b('scrollbar') },
@@ -39,7 +39,7 @@ export declare const HighlightTableBlock: {
39
39
  type: string;
40
40
  items: {
41
41
  type: string;
42
- enum: string[];
42
+ enum: number[];
43
43
  };
44
44
  };
45
45
  type: {};
@@ -33,7 +33,7 @@ export const HighlightTableBlock = {
33
33
  type: 'array',
34
34
  items: {
35
35
  type: 'string',
36
- enum: ['xxl', 'xl', 'l', 'm', 's', 'xs'],
36
+ enum: [12, 6, 4, 3, 2],
37
37
  },
38
38
  } }),
39
39
  } }),
@@ -267,7 +267,7 @@ export interface TableBlockProps {
267
267
  }
268
268
  export interface HighlightTableData {
269
269
  content: string[][];
270
- customColumnWidth?: ('xxl' | 'xl' | 'l' | 'm' | 's' | 'xs')[];
270
+ customColumnWidth?: (12 | 6 | 4 | 3 | 2)[];
271
271
  justify?: ('left' | 'right' | 'center')[];
272
272
  highlighter?: string[];
273
273
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doyourjob/gravity-ui-page-constructor",
3
- "version": "5.31.21",
3
+ "version": "5.31.22",
4
4
  "description": "Gravity UI Page Constructor",
5
5
  "license": "MIT",
6
6
  "repository": {