@gravity-ui/page-constructor 1.16.1 → 1.16.3

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.16.3](https://github.com/gravity-ui/page-constructor/compare/v1.16.2...v1.16.3) (2023-02-17)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * add router link for banner button ([#158](https://github.com/gravity-ui/page-constructor/issues/158)) ([a194a40](https://github.com/gravity-ui/page-constructor/commit/a194a40bae0486277d0a862e3a9b415404d75d0b))
9
+ * **Foldable:** fix issues with content height calculation on resize ([#156](https://github.com/gravity-ui/page-constructor/issues/156)) ([e20709e](https://github.com/gravity-ui/page-constructor/commit/e20709e4eb84e7eb620ff2e42dd3e5010d1066a2))
10
+
11
+ ## [1.16.2](https://github.com/gravity-ui/page-constructor/compare/v1.16.1...v1.16.2) (2023-02-16)
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * **HubspotForm:** required checkbox ([#154](https://github.com/gravity-ui/page-constructor/issues/154)) ([6c948d1](https://github.com/gravity-ui/page-constructor/commit/6c948d1a3511e16902e6808d83ac3f0ac14b6d9c))
17
+
3
18
  ## [1.16.1](https://github.com/gravity-ui/page-constructor/compare/v1.16.0...v1.16.1) (2023-02-14)
4
19
 
5
20
 
@@ -1,7 +1,10 @@
1
1
  /* use this for style redefinitions to awoid problems with
2
2
  unpredictable css rules order in build */
3
- .pc-foldable-block__content-container {
3
+ .pc-foldable-block {
4
4
  height: 0;
5
5
  overflow-y: hidden;
6
6
  transition: height 300ms, margin-bottom 300ms;
7
+ }
8
+ .pc-foldable-block__content-container {
9
+ overflow: auto;
7
10
  }
@@ -3,21 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const react_1 = tslib_1.__importStar(require("react"));
5
5
  const utils_1 = require("../../utils");
6
- const HeightCalculator_1 = tslib_1.__importDefault(require("../../components/HeightCalculator/HeightCalculator"));
6
+ const useHeightCalculator_1 = tslib_1.__importDefault(require("../../hooks/useHeightCalculator"));
7
7
  const b = (0, utils_1.block)('foldable-block');
8
8
  const Foldable = ({ isOpened, children, className }) => {
9
+ const blockRef = (0, react_1.useRef)(null);
9
10
  const contentRef = (0, react_1.useRef)(null);
10
- const [contentHeight, setContentHeight] = (0, react_1.useState)();
11
- const onHeightCalculation = (0, react_1.useCallback)((height) => {
12
- setContentHeight(height);
13
- }, []);
11
+ const contentHeight = (0, useHeightCalculator_1.default)(contentRef);
14
12
  (0, react_1.useEffect)(() => {
15
- if (contentRef && contentRef.current) {
16
- contentRef.current.style.height = isOpened ? `${contentHeight}px` : '0';
13
+ if (blockRef && blockRef.current) {
14
+ blockRef.current.style.height = isOpened && contentHeight ? `${contentHeight}px` : '0';
17
15
  }
18
16
  }, [isOpened, contentHeight]);
19
- return (react_1.default.createElement("div", { className: b(null, className) },
20
- react_1.default.createElement("div", { ref: contentRef, className: b('content-container', { open: isOpened }) }, children),
21
- react_1.default.createElement(HeightCalculator_1.default, { onCalculate: onHeightCalculation }, children)));
17
+ return (react_1.default.createElement("div", { ref: blockRef, className: b({ open: isOpened }, className) },
18
+ react_1.default.createElement("div", { ref: contentRef, className: b('content-container') }, children)));
22
19
  };
23
20
  exports.default = Foldable;
@@ -2,5 +2,9 @@ import { WithChildren } from '../../models';
2
2
  export interface HeightCalculatorProps {
3
3
  onCalculate: (height: number) => void;
4
4
  }
5
+ /**
6
+ * @deprecated Will be removed, use the useHeightCalculator hook instead.
7
+ * @returns The HeightCalculator component.
8
+ */
5
9
  declare const HeightCalculator: ({ onCalculate, children }: WithChildren<HeightCalculatorProps>) => JSX.Element | null;
6
10
  export default HeightCalculator;
@@ -5,6 +5,10 @@ const react_1 = tslib_1.__importStar(require("react"));
5
5
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
6
6
  const utils_1 = require("../../utils");
7
7
  const b = (0, utils_1.block)('height-calculator');
8
+ /**
9
+ * @deprecated Will be removed, use the useHeightCalculator hook instead.
10
+ * @returns The HeightCalculator component.
11
+ */
8
12
  const HeightCalculator = ({ onCalculate, children }) => {
9
13
  const [isCalculating, setIsCalculating] = (0, react_1.useState)(true);
10
14
  const container = (0, react_1.useRef)(null);
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ type HeightCalculatorOptions = {
3
+ recalculateOnResizeDelay: number;
4
+ };
5
+ declare const useHeightCalculator: (containerRef: React.RefObject<HTMLElement>, options?: HeightCalculatorOptions) => number | undefined;
6
+ export default useHeightCalculator;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const react_1 = require("react");
5
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
6
+ const DEFAULT_RECALCULATE_ON_RESIZE_DELAY = 1000;
7
+ const DEFAULT_OPTIONS = {
8
+ recalculateOnResizeDelay: DEFAULT_RECALCULATE_ON_RESIZE_DELAY,
9
+ };
10
+ const useHeightCalculator = (containerRef, options = DEFAULT_OPTIONS) => {
11
+ const recalculateOnResizeDelay = options.recalculateOnResizeDelay;
12
+ const [containerHeight, setContainerHeight] = (0, react_1.useState)(undefined);
13
+ const calculateContainerHeight = (0, react_1.useCallback)(() => {
14
+ if (containerRef.current && containerRef.current.offsetHeight !== containerHeight)
15
+ setContainerHeight(containerRef.current.offsetHeight);
16
+ }, [containerRef, containerHeight, setContainerHeight]);
17
+ (0, react_1.useEffect)(() => {
18
+ const handleResize = lodash_1.default.debounce(calculateContainerHeight, recalculateOnResizeDelay);
19
+ calculateContainerHeight();
20
+ window.addEventListener('resize', handleResize);
21
+ return () => {
22
+ window.removeEventListener('resize', handleResize);
23
+ };
24
+ }, [calculateContainerHeight, recalculateOnResizeDelay]);
25
+ return containerHeight;
26
+ };
27
+ exports.default = useHeightCalculator;
@@ -21,7 +21,8 @@ const BannerCard = (props) => {
21
21
  react_1.default.createElement("h2", { className: b('title') },
22
22
  react_1.default.createElement(components_1.HTML, null, title)),
23
23
  subtitle && (react_1.default.createElement(components_1.YFMWrapper, { className: b('subtitle'), content: subtitle, modifiers: { constructor: true } }))),
24
- react_1.default.createElement(components_1.Button, { className: b('button'), theme: "raised", size: "xl", text: text, url: url, target: target })),
24
+ react_1.default.createElement(components_1.RouterLink, { href: url },
25
+ react_1.default.createElement(components_1.Button, { className: b('button'), theme: "raised", size: "xl", text: text, url: url, target: target }))),
25
26
  react_1.default.createElement(components_1.BackgroundImage, { className: b('image'), src: (0, utils_1.getThemedValue)(image, theme), disableCompress: disableCompress }))));
26
27
  };
27
28
  exports.BannerCard = BannerCard;
@@ -126,9 +126,9 @@ unpredictable css rules order in build */
126
126
  opacity: 0;
127
127
  flex-shrink: 0;
128
128
  }
129
- .pc-hubspot-form .hs-form-field .hs-form-checkbox-display span,
130
- .pc-hubspot-form .hs-form-field .hs-form-booleancheckbox-display span,
131
- .pc-hubspot-form .hs-form-field .hs-form-radio-display span {
129
+ .pc-hubspot-form .hs-form-field .hs-form-checkbox-display span:not(.hs-form-required),
130
+ .pc-hubspot-form .hs-form-field .hs-form-booleancheckbox-display span:not(.hs-form-required),
131
+ .pc-hubspot-form .hs-form-field .hs-form-radio-display span:not(.hs-form-required) {
132
132
  color: var(--yc-color-text-primary);
133
133
  font-size: var(--yc-text-body-2-font-size);
134
134
  line-height: 16px;
@@ -136,12 +136,17 @@ unpredictable css rules order in build */
136
136
  margin: 0;
137
137
  flex-grow: 1;
138
138
  }
139
+ .pc-hubspot-form .hs-form-field .hs-form-checkbox-display .hs-form-required,
140
+ .pc-hubspot-form .hs-form-field .hs-form-booleancheckbox-display .hs-form-required,
141
+ .pc-hubspot-form .hs-form-field .hs-form-radio-display .hs-form-required {
142
+ top: 0;
143
+ }
139
144
  .pc-hubspot-form .hs-form-field .hs-form-booleancheckbox-display,
140
145
  .pc-hubspot-form .hs-form-field .hs-form-checkbox-display {
141
146
  position: relative;
142
147
  }
143
- .pc-hubspot-form .hs-form-field .hs-form-booleancheckbox-display span:before,
144
- .pc-hubspot-form .hs-form-field .hs-form-checkbox-display span:before {
148
+ .pc-hubspot-form .hs-form-field .hs-form-booleancheckbox-display span:not(.hs-form-required):before,
149
+ .pc-hubspot-form .hs-form-field .hs-form-checkbox-display span:not(.hs-form-required):before {
145
150
  content: "";
146
151
  position: absolute;
147
152
  top: 0;
@@ -153,8 +158,8 @@ unpredictable css rules order in build */
153
158
  border: 1px solid var(--yc-color-line-generic-accent);
154
159
  transition: background-color 0.1s linear;
155
160
  }
156
- .pc-hubspot-form .hs-form-field .hs-form-booleancheckbox-display span:after,
157
- .pc-hubspot-form .hs-form-field .hs-form-checkbox-display span:after {
161
+ .pc-hubspot-form .hs-form-field .hs-form-booleancheckbox-display span:not(.hs-form-required):after,
162
+ .pc-hubspot-form .hs-form-field .hs-form-checkbox-display span:not(.hs-form-required):after {
158
163
  content: "";
159
164
  position: absolute;
160
165
  top: -10px;
@@ -1,7 +1,10 @@
1
1
  /* use this for style redefinitions to awoid problems with
2
2
  unpredictable css rules order in build */
3
- .pc-foldable-block__content-container {
3
+ .pc-foldable-block {
4
4
  height: 0;
5
5
  overflow-y: hidden;
6
6
  transition: height 300ms, margin-bottom 300ms;
7
+ }
8
+ .pc-foldable-block__content-container {
9
+ overflow: auto;
7
10
  }
@@ -1,21 +1,18 @@
1
- import React, { useRef, useState, useCallback, useEffect } from 'react';
1
+ import React, { useRef, useEffect } from 'react';
2
2
  import { block } from '../../utils';
3
- import HeightCalculator from '../../components/HeightCalculator/HeightCalculator';
3
+ import useHeightCalculator from '../../hooks/useHeightCalculator';
4
4
  import './Foldable.css';
5
5
  const b = block('foldable-block');
6
6
  const Foldable = ({ isOpened, children, className }) => {
7
+ const blockRef = useRef(null);
7
8
  const contentRef = useRef(null);
8
- const [contentHeight, setContentHeight] = useState();
9
- const onHeightCalculation = useCallback((height) => {
10
- setContentHeight(height);
11
- }, []);
9
+ const contentHeight = useHeightCalculator(contentRef);
12
10
  useEffect(() => {
13
- if (contentRef && contentRef.current) {
14
- contentRef.current.style.height = isOpened ? `${contentHeight}px` : '0';
11
+ if (blockRef && blockRef.current) {
12
+ blockRef.current.style.height = isOpened && contentHeight ? `${contentHeight}px` : '0';
15
13
  }
16
14
  }, [isOpened, contentHeight]);
17
- return (React.createElement("div", { className: b(null, className) },
18
- React.createElement("div", { ref: contentRef, className: b('content-container', { open: isOpened }) }, children),
19
- React.createElement(HeightCalculator, { onCalculate: onHeightCalculation }, children)));
15
+ return (React.createElement("div", { ref: blockRef, className: b({ open: isOpened }, className) },
16
+ React.createElement("div", { ref: contentRef, className: b('content-container') }, children)));
20
17
  };
21
18
  export default Foldable;
@@ -3,5 +3,9 @@ import './HeightCalculator.css';
3
3
  export interface HeightCalculatorProps {
4
4
  onCalculate: (height: number) => void;
5
5
  }
6
+ /**
7
+ * @deprecated Will be removed, use the useHeightCalculator hook instead.
8
+ * @returns The HeightCalculator component.
9
+ */
6
10
  declare const HeightCalculator: ({ onCalculate, children }: WithChildren<HeightCalculatorProps>) => JSX.Element | null;
7
11
  export default HeightCalculator;
@@ -3,6 +3,10 @@ import _ from 'lodash';
3
3
  import { block } from '../../utils';
4
4
  import './HeightCalculator.css';
5
5
  const b = block('height-calculator');
6
+ /**
7
+ * @deprecated Will be removed, use the useHeightCalculator hook instead.
8
+ * @returns The HeightCalculator component.
9
+ */
6
10
  const HeightCalculator = ({ onCalculate, children }) => {
7
11
  const [isCalculating, setIsCalculating] = useState(true);
8
12
  const container = useRef(null);
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ type HeightCalculatorOptions = {
3
+ recalculateOnResizeDelay: number;
4
+ };
5
+ declare const useHeightCalculator: (containerRef: React.RefObject<HTMLElement>, options?: HeightCalculatorOptions) => number | undefined;
6
+ export default useHeightCalculator;
@@ -0,0 +1,24 @@
1
+ import { useState, useEffect, useCallback } from 'react';
2
+ import _ from 'lodash';
3
+ const DEFAULT_RECALCULATE_ON_RESIZE_DELAY = 1000;
4
+ const DEFAULT_OPTIONS = {
5
+ recalculateOnResizeDelay: DEFAULT_RECALCULATE_ON_RESIZE_DELAY,
6
+ };
7
+ const useHeightCalculator = (containerRef, options = DEFAULT_OPTIONS) => {
8
+ const recalculateOnResizeDelay = options.recalculateOnResizeDelay;
9
+ const [containerHeight, setContainerHeight] = useState(undefined);
10
+ const calculateContainerHeight = useCallback(() => {
11
+ if (containerRef.current && containerRef.current.offsetHeight !== containerHeight)
12
+ setContainerHeight(containerRef.current.offsetHeight);
13
+ }, [containerRef, containerHeight, setContainerHeight]);
14
+ useEffect(() => {
15
+ const handleResize = _.debounce(calculateContainerHeight, recalculateOnResizeDelay);
16
+ calculateContainerHeight();
17
+ window.addEventListener('resize', handleResize);
18
+ return () => {
19
+ window.removeEventListener('resize', handleResize);
20
+ };
21
+ }, [calculateContainerHeight, recalculateOnResizeDelay]);
22
+ return containerHeight;
23
+ };
24
+ export default useHeightCalculator;
@@ -1,6 +1,6 @@
1
1
  import React, { useContext } from 'react';
2
2
  import { block, getThemedValue } from '../../utils';
3
- import { Button, YFMWrapper, BackgroundImage, HTML } from '../../components';
3
+ import { Button, YFMWrapper, BackgroundImage, HTML, RouterLink } from '../../components';
4
4
  import { ThemeValueContext } from '../../context/theme/ThemeValueContext';
5
5
  import './BannerCard.css';
6
6
  const b = block('banner-card');
@@ -18,7 +18,8 @@ export const BannerCard = (props) => {
18
18
  React.createElement("h2", { className: b('title') },
19
19
  React.createElement(HTML, null, title)),
20
20
  subtitle && (React.createElement(YFMWrapper, { className: b('subtitle'), content: subtitle, modifiers: { constructor: true } }))),
21
- React.createElement(Button, { className: b('button'), theme: "raised", size: "xl", text: text, url: url, target: target })),
21
+ React.createElement(RouterLink, { href: url },
22
+ React.createElement(Button, { className: b('button'), theme: "raised", size: "xl", text: text, url: url, target: target }))),
22
23
  React.createElement(BackgroundImage, { className: b('image'), src: getThemedValue(image, theme), disableCompress: disableCompress }))));
23
24
  };
24
25
  export default BannerCard;
@@ -126,9 +126,9 @@ unpredictable css rules order in build */
126
126
  opacity: 0;
127
127
  flex-shrink: 0;
128
128
  }
129
- .pc-hubspot-form .hs-form-field .hs-form-checkbox-display span,
130
- .pc-hubspot-form .hs-form-field .hs-form-booleancheckbox-display span,
131
- .pc-hubspot-form .hs-form-field .hs-form-radio-display span {
129
+ .pc-hubspot-form .hs-form-field .hs-form-checkbox-display span:not(.hs-form-required),
130
+ .pc-hubspot-form .hs-form-field .hs-form-booleancheckbox-display span:not(.hs-form-required),
131
+ .pc-hubspot-form .hs-form-field .hs-form-radio-display span:not(.hs-form-required) {
132
132
  color: var(--yc-color-text-primary);
133
133
  font-size: var(--yc-text-body-2-font-size);
134
134
  line-height: 16px;
@@ -136,12 +136,17 @@ unpredictable css rules order in build */
136
136
  margin: 0;
137
137
  flex-grow: 1;
138
138
  }
139
+ .pc-hubspot-form .hs-form-field .hs-form-checkbox-display .hs-form-required,
140
+ .pc-hubspot-form .hs-form-field .hs-form-booleancheckbox-display .hs-form-required,
141
+ .pc-hubspot-form .hs-form-field .hs-form-radio-display .hs-form-required {
142
+ top: 0;
143
+ }
139
144
  .pc-hubspot-form .hs-form-field .hs-form-booleancheckbox-display,
140
145
  .pc-hubspot-form .hs-form-field .hs-form-checkbox-display {
141
146
  position: relative;
142
147
  }
143
- .pc-hubspot-form .hs-form-field .hs-form-booleancheckbox-display span:before,
144
- .pc-hubspot-form .hs-form-field .hs-form-checkbox-display span:before {
148
+ .pc-hubspot-form .hs-form-field .hs-form-booleancheckbox-display span:not(.hs-form-required):before,
149
+ .pc-hubspot-form .hs-form-field .hs-form-checkbox-display span:not(.hs-form-required):before {
145
150
  content: "";
146
151
  position: absolute;
147
152
  top: 0;
@@ -153,8 +158,8 @@ unpredictable css rules order in build */
153
158
  border: 1px solid var(--yc-color-line-generic-accent);
154
159
  transition: background-color 0.1s linear;
155
160
  }
156
- .pc-hubspot-form .hs-form-field .hs-form-booleancheckbox-display span:after,
157
- .pc-hubspot-form .hs-form-field .hs-form-checkbox-display span:after {
161
+ .pc-hubspot-form .hs-form-field .hs-form-booleancheckbox-display span:not(.hs-form-required):after,
162
+ .pc-hubspot-form .hs-form-field .hs-form-checkbox-display span:not(.hs-form-required):after {
158
163
  content: "";
159
164
  position: absolute;
160
165
  top: -10px;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/page-constructor",
3
- "version": "1.16.1",
3
+ "version": "1.16.3",
4
4
  "description": "Gravity UI Page Constructor",
5
5
  "license": "MIT",
6
6
  "repository": {