@gravity-ui/page-constructor 2.0.0-beta.1 → 2.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 (29) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/build/cjs/blocks/Map/schema.d.ts +0 -12
  3. package/build/cjs/components/HTML/HTML.d.ts +1 -1
  4. package/build/cjs/components/Map/GoogleMap.js +7 -5
  5. package/build/cjs/components/Map/Map.css +5 -0
  6. package/build/cjs/components/Map/YMap/YMap.d.ts +4 -2
  7. package/build/cjs/components/Map/YMap/YMap.js +18 -10
  8. package/build/cjs/components/Map/YMap/YandexMap.js +18 -9
  9. package/build/cjs/models/constructor-items/common.d.ts +0 -2
  10. package/build/cjs/navigation/components/Navigation/Navigation.js +7 -6
  11. package/build/cjs/schema/validators/common.d.ts +0 -6
  12. package/build/cjs/schema/validators/common.js +0 -4
  13. package/build/cjs/sub-blocks/Content/Content.css +6 -0
  14. package/build/cjs/sub-blocks/HubspotForm/HubspotForm.css +1 -0
  15. package/build/esm/blocks/Map/schema.d.ts +0 -12
  16. package/build/esm/components/HTML/HTML.d.ts +1 -1
  17. package/build/esm/components/Map/GoogleMap.js +7 -5
  18. package/build/esm/components/Map/Map.css +5 -0
  19. package/build/esm/components/Map/YMap/YMap.d.ts +4 -2
  20. package/build/esm/components/Map/YMap/YMap.js +18 -10
  21. package/build/esm/components/Map/YMap/YandexMap.js +18 -9
  22. package/build/esm/models/constructor-items/common.d.ts +0 -2
  23. package/build/esm/navigation/components/Navigation/Navigation.js +7 -6
  24. package/build/esm/schema/validators/common.d.ts +0 -6
  25. package/build/esm/schema/validators/common.js +0 -4
  26. package/build/esm/sub-blocks/Content/Content.css +6 -0
  27. package/build/esm/sub-blocks/HubspotForm/HubspotForm.css +1 -0
  28. package/package.json +1 -1
  29. package/server/models/constructor-items/common.d.ts +0 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.0.1](https://github.com/gravity-ui/page-constructor/compare/v2.0.0...v2.0.1) (2023-03-24)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * handle margins for centered links and buttons in Content ([#223](https://github.com/gravity-ui/page-constructor/issues/223)) ([50590f2](https://github.com/gravity-ui/page-constructor/commit/50590f288cba7d3dd88e4f91e1642d0a34061fb9))
9
+ * **Navigation:** fix issue with remaining event handler in effect ([#220](https://github.com/gravity-ui/page-constructor/issues/220)) ([d494523](https://github.com/gravity-ui/page-constructor/commit/d4945238ee52f7cca92ea4b092f0701ab4d99693))
10
+
11
+ ## [2.0.0](https://github.com/gravity-ui/page-constructor/compare/v1.25.2...v2.0.0) (2023-03-23)
12
+
13
+
14
+ ### ⚠ BREAKING CHANGES
15
+
16
+ * update uikit up to 4, update react up to 18([#134](https://github.com/gravity-ui/page-constructor/issues/134)) (#212)
17
+
18
+ ### Features
19
+
20
+ * map-block changing the logic of zoom and center ([#219](https://github.com/gravity-ui/page-constructor/issues/219)) ([d332844](https://github.com/gravity-ui/page-constructor/commit/d33284425878cdbfacdf7813826d909e9ab696cb))
21
+ * update uikit up to 4, update react up to 18([#134](https://github.com/gravity-ui/page-constructor/issues/134)) ([#212](https://github.com/gravity-ui/page-constructor/issues/212)) ([377b1f5](https://github.com/gravity-ui/page-constructor/commit/377b1f59c25d08458082232075e2e7bcfe84fe5c))
22
+
3
23
  ## [1.25.2](https://github.com/gravity-ui/page-constructor/compare/v1.25.1...v1.25.2) (2023-03-21)
4
24
 
5
25
 
@@ -6,12 +6,6 @@ export declare const Map: {
6
6
  zoom: {
7
7
  type: string;
8
8
  };
9
- center: {
10
- type: string;
11
- items: {
12
- type: string;
13
- };
14
- };
15
9
  address: {
16
10
  type: string;
17
11
  };
@@ -70,12 +64,6 @@ export declare const MapBlock: {
70
64
  zoom: {
71
65
  type: string;
72
66
  };
73
- center: {
74
- type: string;
75
- items: {
76
- type: string;
77
- };
78
- };
79
67
  address: {
80
68
  type: string;
81
69
  };
@@ -7,7 +7,7 @@ export interface HTMLProps {
7
7
  }
8
8
  declare const HTML: ({ children, block, className }: WithChildren<HTMLProps>) => React.DetailedReactHTMLElement<{
9
9
  dangerouslySetInnerHTML: {
10
- __html: string & (boolean | React.ReactChild | React.ReactFragment | React.ReactPortal | null);
10
+ __html: string | (string & React.ReactElement<any, string | React.JSXElementConstructor<any>>) | (string & React.ReactFragment) | (string & React.ReactPortal);
11
11
  };
12
12
  className: string | undefined;
13
13
  }, HTMLElement> | null;
@@ -8,18 +8,20 @@ const mapsContext_1 = require("../../context/mapsContext/mapsContext");
8
8
  const localeContext_1 = require("../../context/localeContext/localeContext");
9
9
  const mobileContext_1 = require("../../context/mobileContext");
10
10
  const helpers_1 = require("./helpers");
11
+ const configure_1 = require("../../utils/configure");
11
12
  const b = (0, utils_1.block)('map');
12
- function getScriptSrc(apiKey, scriptSrc, address, lang) {
13
- return `${scriptSrc}?key=${apiKey}&language=${lang}&q=${encodeURI(address)}`;
13
+ function getScriptSrc(params) {
14
+ const { apiKey, scriptSrc, address, lang, zoom } = params;
15
+ return `${scriptSrc}?key=${apiKey}&language=${lang}${zoom ? '&zoom=' + zoom : ''}&q=${encodeURI(address)}`;
14
16
  }
15
17
  const GoogleMap = (props) => {
16
- const { address } = props;
18
+ const { address, zoom } = props;
17
19
  const { apiKey, scriptSrc } = (0, react_1.useContext)(mapsContext_1.MapsContext);
18
- const { lang = 'ru' } = (0, react_1.useContext)(localeContext_1.LocaleContext);
20
+ const { lang = configure_1.Lang.Ru } = (0, react_1.useContext)(localeContext_1.LocaleContext);
19
21
  const isMobile = (0, react_1.useContext)(mobileContext_1.MobileContext);
20
22
  const [height, setHeight] = (0, react_1.useState)(undefined);
21
23
  const ref = (0, react_1.useRef)(null);
22
- const src = (0, react_1.useMemo)(() => getScriptSrc(apiKey, scriptSrc, address, lang), [apiKey, scriptSrc, address, lang]);
24
+ const src = (0, react_1.useMemo)(() => getScriptSrc({ apiKey, scriptSrc, address, lang, zoom }), [apiKey, scriptSrc, address, lang, zoom]);
23
25
  (0, react_1.useEffect)(() => {
24
26
  const updateSize = lodash_1.default.debounce(() => {
25
27
  if (ref.current) {
@@ -7,9 +7,13 @@ unpredictable css rules order in build */
7
7
  overflow: hidden;
8
8
  display: flex;
9
9
  }
10
+ .pc-map_hidden {
11
+ opacity: 0;
12
+ }
10
13
  .pc-map__spinner {
11
14
  margin: 0 auto;
12
15
  align-self: center;
16
+ position: absolute;
13
17
  }
14
18
  .pc-map__wrapper {
15
19
  min-height: 300px;
@@ -17,4 +21,5 @@ unpredictable css rules order in build */
17
21
  flex-direction: column;
18
22
  align-items: center;
19
23
  justify-content: center;
24
+ position: relative;
20
25
  }
@@ -1,13 +1,15 @@
1
- import { YMapMarker } from '../../../models';
1
+ import { YMapProps, YMapMarker } from '../../../models';
2
+ type PlacemarksProps = Pick<YMapProps, 'zoom' | 'markers'>;
2
3
  export declare class YMap {
3
4
  private ymap;
4
5
  private mapRef;
5
6
  private coords;
6
7
  constructor(ymap: Ymaps.Map, mapRef: HTMLDivElement | null);
7
- showPlacemarks(markers: YMapMarker[]): Promise<void>;
8
+ showPlacemarks(props: PlacemarksProps): Promise<void>;
8
9
  findAddress(marker: YMapMarker): Promise<void>;
9
10
  findCoordinate(marker: YMapMarker): void;
10
11
  private drawPlaceMarkStyle;
11
12
  private recalcZoomAndCenter;
12
13
  private clearOldPlacemarks;
13
14
  }
15
+ export {};
@@ -22,9 +22,9 @@ class YMap {
22
22
  this.ymap = ymap;
23
23
  this.mapRef = mapRef;
24
24
  }
25
- async showPlacemarks(markers) {
25
+ async showPlacemarks(props) {
26
26
  this.clearOldPlacemarks();
27
- for (const marker of markers) {
27
+ for (const marker of props.markers) {
28
28
  if (marker.address) {
29
29
  await this.findAddress(marker);
30
30
  }
@@ -32,7 +32,7 @@ class YMap {
32
32
  this.findCoordinate(marker);
33
33
  }
34
34
  }
35
- this.recalcZoomAndCenter();
35
+ this.recalcZoomAndCenter(props);
36
36
  }
37
37
  async findAddress(marker) {
38
38
  try {
@@ -52,10 +52,7 @@ class YMap {
52
52
  this.ymap.geoObjects.add(geoObject);
53
53
  }
54
54
  drawPlaceMarkStyle(geoObject, marker) {
55
- if (!marker.label) {
56
- return;
57
- }
58
- const { iconColor, preset = DEFAULT_PLACEMARKS_PRESET } = marker.label;
55
+ const { iconColor, preset = DEFAULT_PLACEMARKS_PRESET } = marker.label || {};
59
56
  let localIconColor = iconColor;
60
57
  // You can set the preset option together with the iconColor option only if it not a 'Stretchy' preset
61
58
  if (!preset.includes('Stretchy') && !iconColor) {
@@ -68,9 +65,10 @@ class YMap {
68
65
  }
69
66
  });
70
67
  }
71
- recalcZoomAndCenter() {
68
+ recalcZoomAndCenter(props) {
72
69
  var _a, _b;
73
70
  const coordsLength = this.coords.length;
71
+ const { zoom = 0 } = props;
74
72
  if (!coordsLength) {
75
73
  return;
76
74
  }
@@ -79,10 +77,20 @@ class YMap {
79
77
  leftBottom = [Math.min(leftBottom[0], point[0]), Math.min(leftBottom[1], point[1])];
80
78
  rightTop = [Math.max(rightTop[0], point[0]), Math.max(rightTop[1], point[1])];
81
79
  });
82
- const newMapParams = window.ymaps.util.bounds.getCenterAndZoom([leftBottom, rightTop], [(_a = this.mapRef) === null || _a === void 0 ? void 0 : _a.clientWidth, (_b = this.mapRef) === null || _b === void 0 ? void 0 : _b.clientHeight], undefined, { margin: DEFAULT_MAP_CONTROL_BUTTON_HEIGHT });
80
+ let newMapParams = {
81
+ zoom,
82
+ center: [],
83
+ };
84
+ if (zoom) {
85
+ // compute only the center
86
+ newMapParams.center = window.ymaps.util.bounds.getCenter([leftBottom, rightTop]);
87
+ }
88
+ else {
89
+ newMapParams = window.ymaps.util.bounds.getCenterAndZoom([leftBottom, rightTop], [(_a = this.mapRef) === null || _a === void 0 ? void 0 : _a.clientWidth, (_b = this.mapRef) === null || _b === void 0 ? void 0 : _b.clientHeight], undefined, { margin: DEFAULT_MAP_CONTROL_BUTTON_HEIGHT });
90
+ }
83
91
  this.ymap.setCenter(newMapParams.center);
84
92
  // Use default zoom for one placemark
85
- if (coordsLength > 1) {
93
+ if (coordsLength > 1 && !zoom) {
86
94
  this.ymap.setZoom(newMapParams.zoom);
87
95
  }
88
96
  }
@@ -16,8 +16,12 @@ const helpers_1 = require("../helpers");
16
16
  const b = (0, utils_1.block)('map');
17
17
  const DEFAULT_CONTAINER_ID = 'ymap';
18
18
  const DEFAULT_ZOOM = 9;
19
+ // Center - is a required parameter for creating a new map
20
+ // We use this init center to create a map
21
+ // The real center of the map will be calculated later, using the coordinates of the markers
22
+ const INITIAL_CENTER = [0, 0];
19
23
  const YandexMap = (props) => {
20
- const { markers, zoom, center, id } = props;
24
+ const { markers, zoom, id } = props;
21
25
  const { apiKey, scriptSrc, nonce } = (0, react_1.useContext)(mapsContext_1.MapsContext);
22
26
  const isMobile = (0, react_1.useContext)(mobileContext_1.MobileContext);
23
27
  const { lang = 'ru' } = (0, react_1.useContext)(localeContext_1.LocaleContext);
@@ -26,6 +30,7 @@ const YandexMap = (props) => {
26
30
  const [height, setHeight] = (0, react_1.useState)(undefined);
27
31
  const ref = (0, react_1.useRef)(null);
28
32
  const [loading, setLoading] = (0, react_1.useState)(false);
33
+ const [ready, setReady] = (0, react_1.useState)(false);
29
34
  const [attemptsIndex, setAttemptsIndex] = (0, react_1.useState)(0);
30
35
  const onTryAgain = (0, react_1.useCallback)(() => {
31
36
  setAttemptsIndex(attemptsIndex + 1);
@@ -33,20 +38,17 @@ const YandexMap = (props) => {
33
38
  (0, react_1.useEffect)(() => {
34
39
  (async function () {
35
40
  var _a;
36
- if (!center) {
37
- return;
38
- }
39
41
  setLoading(true);
40
42
  await YandexMapApiLoader_1.YMapsApiLoader.loadApi(apiKey, scriptSrc, lang, nonce);
41
43
  (_a = window.ymaps) === null || _a === void 0 ? void 0 : _a.ready(() => {
42
44
  setYmaps(new YMap_1.YMap(new window.ymaps.Map(containerId, {
43
- center,
45
+ center: INITIAL_CENTER,
44
46
  zoom: zoom || DEFAULT_ZOOM,
45
47
  }, { autoFitToViewport: 'always' }), ref.current));
46
48
  });
47
49
  setLoading(false);
48
50
  })();
49
- }, [apiKey, lang, scriptSrc, containerId, zoom, center, nonce, attemptsIndex, setLoading]);
51
+ }, [apiKey, lang, scriptSrc, containerId, zoom, nonce, attemptsIndex, setLoading]);
50
52
  (0, react_1.useEffect)(() => {
51
53
  const updateSize = lodash_1.default.debounce(() => {
52
54
  if (ref.current) {
@@ -61,12 +63,19 @@ const YandexMap = (props) => {
61
63
  }, [markers, ymap, setYmaps, isMobile]);
62
64
  (0, react_1.useEffect)(() => {
63
65
  if (ymap) {
64
- ymap.showPlacemarks(markers);
66
+ // show with computed center and placemarks
67
+ const showPlacemarks = async () => {
68
+ await ymap.showPlacemarks({ markers, zoom });
69
+ setReady(true);
70
+ };
71
+ showPlacemarks();
65
72
  }
66
73
  });
67
- if (!center)
74
+ if (!markers)
68
75
  return null;
69
76
  return (react_1.default.createElement(ErrorWrapper_1.default, { isError: YandexMapApiLoader_1.YMapsApiLoader.status === YandexMapApiLoader_1.MapApiStatus.Error, text: (0, i18n_1.default)('map-load-error'), buttonText: (0, i18n_1.default)('map-try-again'), handler: onTryAgain, className: b('wrapper') },
70
- react_1.default.createElement("div", { id: containerId, className: b(), ref: ref, style: { height } }, loading ? react_1.default.createElement(uikit_1.Spin, { size: "xl", className: b('spinner') }) : null)));
77
+ react_1.default.createElement("div", { className: b('wrapper') },
78
+ react_1.default.createElement("div", { id: containerId, className: b({ hidden: !ready }), ref: ref, style: { height } }),
79
+ loading ? react_1.default.createElement(uikit_1.Spin, { size: "xl", className: b('spinner') }) : null)));
71
80
  };
72
81
  exports.default = YandexMap;
@@ -189,7 +189,6 @@ export interface MediaProps extends Animatable, Partial<MediaComponentDataLensPr
189
189
  export type Coordinate = number[];
190
190
  export interface MapBaseProps {
191
191
  zoom?: number;
192
- center?: Coordinate;
193
192
  }
194
193
  export interface GMapProps extends MapBaseProps {
195
194
  address: string;
@@ -197,7 +196,6 @@ export interface GMapProps extends MapBaseProps {
197
196
  export interface YMapProps extends MapBaseProps {
198
197
  markers: YMapMarker[];
199
198
  id: string;
200
- center: Coordinate;
201
199
  }
202
200
  export interface YMapMarker {
203
201
  address?: string;
@@ -9,6 +9,7 @@ const locationContext_1 = require("../../../context/locationContext");
9
9
  const constants_1 = require("../../constants");
10
10
  const NavigationListItem_1 = require("../NavigationListItem/NavigationListItem");
11
11
  const b = (0, utils_1.block)('navigation');
12
+ const EVENT_HANDLE_DELAY = 100;
12
13
  const Navigation = ({ className, onActiveItemChange, links, activeItemId, highlightActiveItem, }) => {
13
14
  const { asPath, pathname } = (0, react_1.useContext)(locationContext_1.LocationContext);
14
15
  const itemRefs = (0, react_1.useRef)([]);
@@ -24,21 +25,21 @@ const Navigation = ({ className, onActiveItemChange, links, activeItemId, highli
24
25
  }
25
26
  }, []);
26
27
  (0, react_1.useEffect)(() => {
27
- const debouncedCalculateItemPositions = lodash_1.default.debounce(calculateItemPositions, 100);
28
- const calculateOnScroll = lodash_1.default.debounce(() => {
28
+ const debouncedCalculateItemPositions = lodash_1.default.debounce(calculateItemPositions, EVENT_HANDLE_DELAY);
29
+ const debouncedCalculateOnScroll = lodash_1.default.debounce(() => {
29
30
  const curLeftScroll = window.pageXOffset;
30
31
  if (curLeftScroll !== lastLeftScroll) {
31
32
  setLastLeftScroll(window.pageXOffset);
32
33
  calculateItemPositions();
33
34
  }
34
- }, 100);
35
+ }, EVENT_HANDLE_DELAY);
35
36
  calculateItemPositions();
36
37
  setLastLeftScroll(window.pageXOffset);
37
38
  window.addEventListener('resize', debouncedCalculateItemPositions);
38
- window.addEventListener('scroll', calculateOnScroll);
39
+ window.addEventListener('scroll', debouncedCalculateOnScroll);
39
40
  return () => {
40
- window.removeEventListener(`resize`, calculateItemPositions);
41
- window.removeEventListener('scroll', calculateOnScroll);
41
+ window.removeEventListener(`resize`, debouncedCalculateItemPositions);
42
+ window.removeEventListener('scroll', debouncedCalculateOnScroll);
42
43
  };
43
44
  }, [calculateItemPositions, itemRefs, lastLeftScroll]);
44
45
  (0, react_1.useEffect)(() => {
@@ -1168,12 +1168,6 @@ export declare const MapProps: {
1168
1168
  zoom: {
1169
1169
  type: string;
1170
1170
  };
1171
- center: {
1172
- type: string;
1173
- items: {
1174
- type: string;
1175
- };
1176
- };
1177
1171
  address: {
1178
1172
  type: string;
1179
1173
  };
@@ -493,10 +493,6 @@ exports.MapProps = {
493
493
  zoom: {
494
494
  type: 'number',
495
495
  },
496
- center: {
497
- type: 'array',
498
- items: { type: 'number' },
499
- },
500
496
  address: {
501
497
  type: 'string',
502
498
  },
@@ -31,6 +31,9 @@ unpredictable css rules order in build */
31
31
  margin-top: 0;
32
32
  margin-right: 12px;
33
33
  }
34
+ .pc-content__button.pc-content__button:last-child {
35
+ margin-right: 0;
36
+ }
34
37
 
35
38
  .pc-content__links {
36
39
  display: flex;
@@ -41,6 +44,9 @@ unpredictable css rules order in build */
41
44
  display: block;
42
45
  margin-right: 32px;
43
46
  }
47
+ .pc-content__link:last-child {
48
+ margin-right: 0;
49
+ }
44
50
  .pc-content_centered.pc-content_centered {
45
51
  margin: 0 auto;
46
52
  text-align: center;
@@ -268,6 +268,7 @@ unpredictable css rules order in build */
268
268
  .pc-hubspot-form .hs-button.primary {
269
269
  margin: 0;
270
270
  padding: 0;
271
+ font-family: var(--yc-text-body-font-family);
271
272
  font-size: inherit;
272
273
  font-weight: 400;
273
274
  color: inherit;
@@ -6,12 +6,6 @@ export declare const Map: {
6
6
  zoom: {
7
7
  type: string;
8
8
  };
9
- center: {
10
- type: string;
11
- items: {
12
- type: string;
13
- };
14
- };
15
9
  address: {
16
10
  type: string;
17
11
  };
@@ -70,12 +64,6 @@ export declare const MapBlock: {
70
64
  zoom: {
71
65
  type: string;
72
66
  };
73
- center: {
74
- type: string;
75
- items: {
76
- type: string;
77
- };
78
- };
79
67
  address: {
80
68
  type: string;
81
69
  };
@@ -7,7 +7,7 @@ export interface HTMLProps {
7
7
  }
8
8
  declare const HTML: ({ children, block, className }: WithChildren<HTMLProps>) => React.DetailedReactHTMLElement<{
9
9
  dangerouslySetInnerHTML: {
10
- __html: string & (boolean | React.ReactChild | React.ReactFragment | React.ReactPortal | null);
10
+ __html: string | (string & React.ReactElement<any, string | React.JSXElementConstructor<any>>) | (string & React.ReactFragment) | (string & React.ReactPortal);
11
11
  };
12
12
  className: string | undefined;
13
13
  }, HTMLElement> | null;
@@ -5,18 +5,20 @@ import { MapsContext } from '../../context/mapsContext/mapsContext';
5
5
  import { LocaleContext } from '../../context/localeContext/localeContext';
6
6
  import { MobileContext } from '../../context/mobileContext';
7
7
  import { getMapHeight } from './helpers';
8
+ import { Lang } from '../../utils/configure';
8
9
  const b = block('map');
9
- function getScriptSrc(apiKey, scriptSrc, address, lang) {
10
- return `${scriptSrc}?key=${apiKey}&language=${lang}&q=${encodeURI(address)}`;
10
+ function getScriptSrc(params) {
11
+ const { apiKey, scriptSrc, address, lang, zoom } = params;
12
+ return `${scriptSrc}?key=${apiKey}&language=${lang}${zoom ? '&zoom=' + zoom : ''}&q=${encodeURI(address)}`;
11
13
  }
12
14
  const GoogleMap = (props) => {
13
- const { address } = props;
15
+ const { address, zoom } = props;
14
16
  const { apiKey, scriptSrc } = useContext(MapsContext);
15
- const { lang = 'ru' } = useContext(LocaleContext);
17
+ const { lang = Lang.Ru } = useContext(LocaleContext);
16
18
  const isMobile = useContext(MobileContext);
17
19
  const [height, setHeight] = useState(undefined);
18
20
  const ref = useRef(null);
19
- const src = useMemo(() => getScriptSrc(apiKey, scriptSrc, address, lang), [apiKey, scriptSrc, address, lang]);
21
+ const src = useMemo(() => getScriptSrc({ apiKey, scriptSrc, address, lang, zoom }), [apiKey, scriptSrc, address, lang, zoom]);
20
22
  useEffect(() => {
21
23
  const updateSize = _.debounce(() => {
22
24
  if (ref.current) {
@@ -7,9 +7,13 @@ unpredictable css rules order in build */
7
7
  overflow: hidden;
8
8
  display: flex;
9
9
  }
10
+ .pc-map_hidden {
11
+ opacity: 0;
12
+ }
10
13
  .pc-map__spinner {
11
14
  margin: 0 auto;
12
15
  align-self: center;
16
+ position: absolute;
13
17
  }
14
18
  .pc-map__wrapper {
15
19
  min-height: 300px;
@@ -17,4 +21,5 @@ unpredictable css rules order in build */
17
21
  flex-direction: column;
18
22
  align-items: center;
19
23
  justify-content: center;
24
+ position: relative;
20
25
  }
@@ -1,13 +1,15 @@
1
- import { YMapMarker } from '../../../models';
1
+ import { YMapProps, YMapMarker } from '../../../models';
2
+ type PlacemarksProps = Pick<YMapProps, 'zoom' | 'markers'>;
2
3
  export declare class YMap {
3
4
  private ymap;
4
5
  private mapRef;
5
6
  private coords;
6
7
  constructor(ymap: Ymaps.Map, mapRef: HTMLDivElement | null);
7
- showPlacemarks(markers: YMapMarker[]): Promise<void>;
8
+ showPlacemarks(props: PlacemarksProps): Promise<void>;
8
9
  findAddress(marker: YMapMarker): Promise<void>;
9
10
  findCoordinate(marker: YMapMarker): void;
10
11
  private drawPlaceMarkStyle;
11
12
  private recalcZoomAndCenter;
12
13
  private clearOldPlacemarks;
13
14
  }
15
+ export {};
@@ -19,9 +19,9 @@ export class YMap {
19
19
  this.ymap = ymap;
20
20
  this.mapRef = mapRef;
21
21
  }
22
- async showPlacemarks(markers) {
22
+ async showPlacemarks(props) {
23
23
  this.clearOldPlacemarks();
24
- for (const marker of markers) {
24
+ for (const marker of props.markers) {
25
25
  if (marker.address) {
26
26
  await this.findAddress(marker);
27
27
  }
@@ -29,7 +29,7 @@ export class YMap {
29
29
  this.findCoordinate(marker);
30
30
  }
31
31
  }
32
- this.recalcZoomAndCenter();
32
+ this.recalcZoomAndCenter(props);
33
33
  }
34
34
  async findAddress(marker) {
35
35
  try {
@@ -49,10 +49,7 @@ export class YMap {
49
49
  this.ymap.geoObjects.add(geoObject);
50
50
  }
51
51
  drawPlaceMarkStyle(geoObject, marker) {
52
- if (!marker.label) {
53
- return;
54
- }
55
- const { iconColor, preset = DEFAULT_PLACEMARKS_PRESET } = marker.label;
52
+ const { iconColor, preset = DEFAULT_PLACEMARKS_PRESET } = marker.label || {};
56
53
  let localIconColor = iconColor;
57
54
  // You can set the preset option together with the iconColor option only if it not a 'Stretchy' preset
58
55
  if (!preset.includes('Stretchy') && !iconColor) {
@@ -65,9 +62,10 @@ export class YMap {
65
62
  }
66
63
  });
67
64
  }
68
- recalcZoomAndCenter() {
65
+ recalcZoomAndCenter(props) {
69
66
  var _a, _b;
70
67
  const coordsLength = this.coords.length;
68
+ const { zoom = 0 } = props;
71
69
  if (!coordsLength) {
72
70
  return;
73
71
  }
@@ -76,10 +74,20 @@ export class YMap {
76
74
  leftBottom = [Math.min(leftBottom[0], point[0]), Math.min(leftBottom[1], point[1])];
77
75
  rightTop = [Math.max(rightTop[0], point[0]), Math.max(rightTop[1], point[1])];
78
76
  });
79
- const newMapParams = window.ymaps.util.bounds.getCenterAndZoom([leftBottom, rightTop], [(_a = this.mapRef) === null || _a === void 0 ? void 0 : _a.clientWidth, (_b = this.mapRef) === null || _b === void 0 ? void 0 : _b.clientHeight], undefined, { margin: DEFAULT_MAP_CONTROL_BUTTON_HEIGHT });
77
+ let newMapParams = {
78
+ zoom,
79
+ center: [],
80
+ };
81
+ if (zoom) {
82
+ // compute only the center
83
+ newMapParams.center = window.ymaps.util.bounds.getCenter([leftBottom, rightTop]);
84
+ }
85
+ else {
86
+ newMapParams = window.ymaps.util.bounds.getCenterAndZoom([leftBottom, rightTop], [(_a = this.mapRef) === null || _a === void 0 ? void 0 : _a.clientWidth, (_b = this.mapRef) === null || _b === void 0 ? void 0 : _b.clientHeight], undefined, { margin: DEFAULT_MAP_CONTROL_BUTTON_HEIGHT });
87
+ }
80
88
  this.ymap.setCenter(newMapParams.center);
81
89
  // Use default zoom for one placemark
82
- if (coordsLength > 1) {
90
+ if (coordsLength > 1 && !zoom) {
83
91
  this.ymap.setZoom(newMapParams.zoom);
84
92
  }
85
93
  }
@@ -13,8 +13,12 @@ import { getMapHeight } from '../helpers';
13
13
  const b = block('map');
14
14
  const DEFAULT_CONTAINER_ID = 'ymap';
15
15
  const DEFAULT_ZOOM = 9;
16
+ // Center - is a required parameter for creating a new map
17
+ // We use this init center to create a map
18
+ // The real center of the map will be calculated later, using the coordinates of the markers
19
+ const INITIAL_CENTER = [0, 0];
16
20
  const YandexMap = (props) => {
17
- const { markers, zoom, center, id } = props;
21
+ const { markers, zoom, id } = props;
18
22
  const { apiKey, scriptSrc, nonce } = useContext(MapsContext);
19
23
  const isMobile = useContext(MobileContext);
20
24
  const { lang = 'ru' } = useContext(LocaleContext);
@@ -23,6 +27,7 @@ const YandexMap = (props) => {
23
27
  const [height, setHeight] = useState(undefined);
24
28
  const ref = useRef(null);
25
29
  const [loading, setLoading] = useState(false);
30
+ const [ready, setReady] = useState(false);
26
31
  const [attemptsIndex, setAttemptsIndex] = useState(0);
27
32
  const onTryAgain = useCallback(() => {
28
33
  setAttemptsIndex(attemptsIndex + 1);
@@ -30,20 +35,17 @@ const YandexMap = (props) => {
30
35
  useEffect(() => {
31
36
  (async function () {
32
37
  var _a;
33
- if (!center) {
34
- return;
35
- }
36
38
  setLoading(true);
37
39
  await YMapsApiLoader.loadApi(apiKey, scriptSrc, lang, nonce);
38
40
  (_a = window.ymaps) === null || _a === void 0 ? void 0 : _a.ready(() => {
39
41
  setYmaps(new YMap(new window.ymaps.Map(containerId, {
40
- center,
42
+ center: INITIAL_CENTER,
41
43
  zoom: zoom || DEFAULT_ZOOM,
42
44
  }, { autoFitToViewport: 'always' }), ref.current));
43
45
  });
44
46
  setLoading(false);
45
47
  })();
46
- }, [apiKey, lang, scriptSrc, containerId, zoom, center, nonce, attemptsIndex, setLoading]);
48
+ }, [apiKey, lang, scriptSrc, containerId, zoom, nonce, attemptsIndex, setLoading]);
47
49
  useEffect(() => {
48
50
  const updateSize = _.debounce(() => {
49
51
  if (ref.current) {
@@ -58,12 +60,19 @@ const YandexMap = (props) => {
58
60
  }, [markers, ymap, setYmaps, isMobile]);
59
61
  useEffect(() => {
60
62
  if (ymap) {
61
- ymap.showPlacemarks(markers);
63
+ // show with computed center and placemarks
64
+ const showPlacemarks = async () => {
65
+ await ymap.showPlacemarks({ markers, zoom });
66
+ setReady(true);
67
+ };
68
+ showPlacemarks();
62
69
  }
63
70
  });
64
- if (!center)
71
+ if (!markers)
65
72
  return null;
66
73
  return (React.createElement(ErrorWrapper, { isError: YMapsApiLoader.status === MapApiStatus.Error, text: i18n('map-load-error'), buttonText: i18n('map-try-again'), handler: onTryAgain, className: b('wrapper') },
67
- React.createElement("div", { id: containerId, className: b(), ref: ref, style: { height } }, loading ? React.createElement(Spin, { size: "xl", className: b('spinner') }) : null)));
74
+ React.createElement("div", { className: b('wrapper') },
75
+ React.createElement("div", { id: containerId, className: b({ hidden: !ready }), ref: ref, style: { height } }),
76
+ loading ? React.createElement(Spin, { size: "xl", className: b('spinner') }) : null)));
68
77
  };
69
78
  export default YandexMap;
@@ -189,7 +189,6 @@ export interface MediaProps extends Animatable, Partial<MediaComponentDataLensPr
189
189
  export type Coordinate = number[];
190
190
  export interface MapBaseProps {
191
191
  zoom?: number;
192
- center?: Coordinate;
193
192
  }
194
193
  export interface GMapProps extends MapBaseProps {
195
194
  address: string;
@@ -197,7 +196,6 @@ export interface GMapProps extends MapBaseProps {
197
196
  export interface YMapProps extends MapBaseProps {
198
197
  markers: YMapMarker[];
199
198
  id: string;
200
- center: Coordinate;
201
199
  }
202
200
  export interface YMapMarker {
203
201
  address?: string;
@@ -7,6 +7,7 @@ import { ItemColumnName } from '../../constants';
7
7
  import { NavigationListItem } from '../NavigationListItem/NavigationListItem';
8
8
  import './Navigation.css';
9
9
  const b = block('navigation');
10
+ const EVENT_HANDLE_DELAY = 100;
10
11
  const Navigation = ({ className, onActiveItemChange, links, activeItemId, highlightActiveItem, }) => {
11
12
  const { asPath, pathname } = useContext(LocationContext);
12
13
  const itemRefs = useRef([]);
@@ -22,21 +23,21 @@ const Navigation = ({ className, onActiveItemChange, links, activeItemId, highli
22
23
  }
23
24
  }, []);
24
25
  useEffect(() => {
25
- const debouncedCalculateItemPositions = _.debounce(calculateItemPositions, 100);
26
- const calculateOnScroll = _.debounce(() => {
26
+ const debouncedCalculateItemPositions = _.debounce(calculateItemPositions, EVENT_HANDLE_DELAY);
27
+ const debouncedCalculateOnScroll = _.debounce(() => {
27
28
  const curLeftScroll = window.pageXOffset;
28
29
  if (curLeftScroll !== lastLeftScroll) {
29
30
  setLastLeftScroll(window.pageXOffset);
30
31
  calculateItemPositions();
31
32
  }
32
- }, 100);
33
+ }, EVENT_HANDLE_DELAY);
33
34
  calculateItemPositions();
34
35
  setLastLeftScroll(window.pageXOffset);
35
36
  window.addEventListener('resize', debouncedCalculateItemPositions);
36
- window.addEventListener('scroll', calculateOnScroll);
37
+ window.addEventListener('scroll', debouncedCalculateOnScroll);
37
38
  return () => {
38
- window.removeEventListener(`resize`, calculateItemPositions);
39
- window.removeEventListener('scroll', calculateOnScroll);
39
+ window.removeEventListener(`resize`, debouncedCalculateItemPositions);
40
+ window.removeEventListener('scroll', debouncedCalculateOnScroll);
40
41
  };
41
42
  }, [calculateItemPositions, itemRefs, lastLeftScroll]);
42
43
  useEffect(() => {
@@ -1168,12 +1168,6 @@ export declare const MapProps: {
1168
1168
  zoom: {
1169
1169
  type: string;
1170
1170
  };
1171
- center: {
1172
- type: string;
1173
- items: {
1174
- type: string;
1175
- };
1176
- };
1177
1171
  address: {
1178
1172
  type: string;
1179
1173
  };
@@ -489,10 +489,6 @@ export const MapProps = {
489
489
  zoom: {
490
490
  type: 'number',
491
491
  },
492
- center: {
493
- type: 'array',
494
- items: { type: 'number' },
495
- },
496
492
  address: {
497
493
  type: 'string',
498
494
  },
@@ -31,6 +31,9 @@ unpredictable css rules order in build */
31
31
  margin-top: 0;
32
32
  margin-right: 12px;
33
33
  }
34
+ .pc-content__button.pc-content__button:last-child {
35
+ margin-right: 0;
36
+ }
34
37
 
35
38
  .pc-content__links {
36
39
  display: flex;
@@ -41,6 +44,9 @@ unpredictable css rules order in build */
41
44
  display: block;
42
45
  margin-right: 32px;
43
46
  }
47
+ .pc-content__link:last-child {
48
+ margin-right: 0;
49
+ }
44
50
  .pc-content_centered.pc-content_centered {
45
51
  margin: 0 auto;
46
52
  text-align: center;
@@ -268,6 +268,7 @@ unpredictable css rules order in build */
268
268
  .pc-hubspot-form .hs-button.primary {
269
269
  margin: 0;
270
270
  padding: 0;
271
+ font-family: var(--yc-text-body-font-family);
271
272
  font-size: inherit;
272
273
  font-weight: 400;
273
274
  color: inherit;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/page-constructor",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.1",
4
4
  "description": "Gravity UI Page Constructor",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -189,7 +189,6 @@ export interface MediaProps extends Animatable, Partial<MediaComponentDataLensPr
189
189
  export type Coordinate = number[];
190
190
  export interface MapBaseProps {
191
191
  zoom?: number;
192
- center?: Coordinate;
193
192
  }
194
193
  export interface GMapProps extends MapBaseProps {
195
194
  address: string;
@@ -197,7 +196,6 @@ export interface GMapProps extends MapBaseProps {
197
196
  export interface YMapProps extends MapBaseProps {
198
197
  markers: YMapMarker[];
199
198
  id: string;
200
- center: Coordinate;
201
199
  }
202
200
  export interface YMapMarker {
203
201
  address?: string;