@gravity-ui/page-constructor 7.15.1 → 7.17.0

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 (51) hide show
  1. package/build/cjs/blocks/Map/Map.js.map +1 -1
  2. package/build/cjs/blocks/Map/schema.d.ts +90 -0
  3. package/build/cjs/components/Map/GoogleMap.js +6 -2
  4. package/build/cjs/components/Map/GoogleMap.js.map +1 -1
  5. package/build/cjs/components/Map/YMap/YMap.d.ts +4 -4
  6. package/build/cjs/components/Map/YMap/YMap.js +46 -15
  7. package/build/cjs/components/Map/YMap/YMap.js.map +1 -1
  8. package/build/cjs/components/Map/YMap/YandexMap.js +35 -6
  9. package/build/cjs/components/Map/YMap/YandexMap.js.map +1 -1
  10. package/build/cjs/components/Map/YMap/utils.d.ts +8 -0
  11. package/build/cjs/components/Map/YMap/utils.js +96 -0
  12. package/build/cjs/components/Map/YMap/utils.js.map +1 -0
  13. package/build/cjs/components/index.d.ts +1 -0
  14. package/build/cjs/components/index.js +3 -1
  15. package/build/cjs/components/index.js.map +1 -1
  16. package/build/cjs/internal-typings/global.d.ts +4 -2
  17. package/build/cjs/models/constructor-items/blocks.d.ts +1 -1
  18. package/build/cjs/models/constructor-items/blocks.js.map +1 -1
  19. package/build/cjs/models/constructor-items/common.d.ts +19 -1
  20. package/build/cjs/models/constructor-items/common.js.map +1 -1
  21. package/build/cjs/schema/validators/common.d.ts +123 -0
  22. package/build/cjs/schema/validators/common.js +30 -0
  23. package/build/cjs/schema/validators/common.js.map +1 -1
  24. package/build/esm/blocks/Map/Map.js.map +1 -1
  25. package/build/esm/blocks/Map/schema.d.ts +90 -0
  26. package/build/esm/components/Map/GoogleMap.js +6 -2
  27. package/build/esm/components/Map/GoogleMap.js.map +1 -1
  28. package/build/esm/components/Map/YMap/YMap.d.ts +4 -4
  29. package/build/esm/components/Map/YMap/YMap.js +46 -15
  30. package/build/esm/components/Map/YMap/YMap.js.map +1 -1
  31. package/build/esm/components/Map/YMap/YandexMap.js +35 -6
  32. package/build/esm/components/Map/YMap/YandexMap.js.map +1 -1
  33. package/build/esm/components/Map/YMap/utils.d.ts +8 -0
  34. package/build/esm/components/Map/YMap/utils.js +90 -0
  35. package/build/esm/components/Map/YMap/utils.js.map +1 -0
  36. package/build/esm/components/index.d.ts +1 -0
  37. package/build/esm/components/index.js +1 -0
  38. package/build/esm/components/index.js.map +1 -1
  39. package/build/esm/internal-typings/global.d.ts +4 -2
  40. package/build/esm/models/constructor-items/blocks.d.ts +1 -1
  41. package/build/esm/models/constructor-items/blocks.js.map +1 -1
  42. package/build/esm/models/constructor-items/common.d.ts +19 -1
  43. package/build/esm/models/constructor-items/common.js.map +1 -1
  44. package/build/esm/schema/validators/common.d.ts +123 -0
  45. package/build/esm/schema/validators/common.js +30 -0
  46. package/build/esm/schema/validators/common.js.map +1 -1
  47. package/package.json +1 -1
  48. package/schema/index.js +1 -1
  49. package/server/models/constructor-items/blocks.d.ts +1 -1
  50. package/server/models/constructor-items/common.d.ts +19 -1
  51. package/widget/index.js +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"Map.js","sourceRoot":"../../../../src","sources":["blocks/Map/Map.tsx"],"names":[],"mappings":";;;;;AAAA,8EAA2C;AAC3C,gGAA6D;AAE7D,gDAAkC;AAClC,kEAA0D;AAI1D,MAAM,CAAC,GAAG,IAAA,aAAK,EAAC,WAAW,CAAC,CAAC;AAEtB,MAAM,QAAQ,GAAG,CAAC,EAAC,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,KAAK,EAAgB,EAAE,EAAE;IAC9E,MAAM,cAAc,GAAG,IAAA,+BAAc,EAAC;QAClC,MAAM;QACN,aAAa;KAChB,CAAC,CAAC;IAEH,OAAO,CACH,uBAAC,mBAAS,OAAK,KAAK,YAChB,uBAAC,mBAAS,CAAC,IAAI,cACX,uBAAC,aAAG,OAAK,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC,EAAC,MAAM,EAAE,cAAc,EAAC,CAAC,GAAI,GAC3C,GACT,CACf,CAAC;AACN,CAAC,CAAC;AAbW,QAAA,QAAQ,YAanB;AAEF,kBAAe,gBAAQ,CAAC","sourcesContent":["import Map from '../../components/Map/Map';\nimport MediaBase from '../../components/MediaBase/MediaBase';\nimport {MapBlockProps} from '../../models';\nimport {block} from '../../utils';\nimport {getMediaBorder} from '../../utils/borderSelector';\n\nimport './Map.scss';\n\nconst b = block('map-block');\n\nexport const MapBlock = ({map, border, disableShadow, ...props}: MapBlockProps) => {\n const borderSelected = getMediaBorder({\n border,\n disableShadow,\n });\n\n return (\n <MediaBase {...props}>\n <MediaBase.Card>\n <Map {...map} className={b({border: borderSelected})} />\n </MediaBase.Card>\n </MediaBase>\n );\n};\n\nexport default MapBlock;\n"]}
1
+ {"version":3,"file":"Map.js","sourceRoot":"../../../../src","sources":["blocks/Map/Map.tsx"],"names":[],"mappings":";;;;;AAAA,8EAA2C;AAC3C,gGAA6D;AAE7D,gDAAkC;AAClC,kEAA0D;AAI1D,MAAM,CAAC,GAAG,IAAA,aAAK,EAAC,WAAW,CAAC,CAAC;AAEtB,MAAM,QAAQ,GAAG,CAAC,EAAC,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,KAAK,EAAgB,EAAE,EAAE;IAC9E,MAAM,cAAc,GAAG,IAAA,+BAAc,EAAC;QAClC,MAAM;QACN,aAAa;KAChB,CAAC,CAAC;IAEH,OAAO,CACH,uBAAC,mBAAS,OAAK,KAAK,YAChB,uBAAC,mBAAS,CAAC,IAAI,cACX,uBAAC,aAAG,OAAM,GAAgB,EAAE,SAAS,EAAE,CAAC,CAAC,EAAC,MAAM,EAAE,cAAc,EAAC,CAAC,GAAI,GACzD,GACT,CACf,CAAC;AACN,CAAC,CAAC;AAbW,QAAA,QAAQ,YAanB;AAEF,kBAAe,gBAAQ,CAAC","sourcesContent":["import Map from '../../components/Map/Map';\nimport MediaBase from '../../components/MediaBase/MediaBase';\nimport {MapBlockProps, MapProps} from '../../models';\nimport {block} from '../../utils';\nimport {getMediaBorder} from '../../utils/borderSelector';\n\nimport './Map.scss';\n\nconst b = block('map-block');\n\nexport const MapBlock = ({map, border, disableShadow, ...props}: MapBlockProps) => {\n const borderSelected = getMediaBorder({\n border,\n disableShadow,\n });\n\n return (\n <MediaBase {...props}>\n <MediaBase.Card>\n <Map {...(map as MapProps)} className={b({border: borderSelected})} />\n </MediaBase.Card>\n </MediaBase>\n );\n};\n\nexport default MapBlock;\n"]}
@@ -41,6 +41,45 @@ export declare const Map: {
41
41
  iconColor: {
42
42
  type: string;
43
43
  };
44
+ iconImageHref: {
45
+ type: string;
46
+ };
47
+ iconImageSize: {
48
+ type: string;
49
+ items: {
50
+ type: string;
51
+ };
52
+ minItems: number;
53
+ maxItems: number;
54
+ };
55
+ iconImageOffset: {
56
+ type: string;
57
+ items: {
58
+ type: string;
59
+ };
60
+ minItems: number;
61
+ maxItems: number;
62
+ };
63
+ iconImageClipRect: {
64
+ type: string;
65
+ items: {
66
+ type: string;
67
+ items: {
68
+ type: string;
69
+ };
70
+ minItems: number;
71
+ maxItems: number;
72
+ };
73
+ minItems: number;
74
+ maxItems: number;
75
+ };
76
+ iconLayout: {
77
+ type: string;
78
+ };
79
+ iconShape: {
80
+ type: string;
81
+ additionalProperties: boolean;
82
+ };
44
83
  preset: {
45
84
  type: string;
46
85
  };
@@ -49,6 +88,12 @@ export declare const Map: {
49
88
  };
50
89
  };
51
90
  };
91
+ disableControls: {
92
+ type: string;
93
+ };
94
+ disableBalloons: {
95
+ type: string;
96
+ };
52
97
  };
53
98
  };
54
99
  export declare const MapBlock: {
@@ -99,6 +144,45 @@ export declare const MapBlock: {
99
144
  iconColor: {
100
145
  type: string;
101
146
  };
147
+ iconImageHref: {
148
+ type: string;
149
+ };
150
+ iconImageSize: {
151
+ type: string;
152
+ items: {
153
+ type: string;
154
+ };
155
+ minItems: number;
156
+ maxItems: number;
157
+ };
158
+ iconImageOffset: {
159
+ type: string;
160
+ items: {
161
+ type: string;
162
+ };
163
+ minItems: number;
164
+ maxItems: number;
165
+ };
166
+ iconImageClipRect: {
167
+ type: string;
168
+ items: {
169
+ type: string;
170
+ items: {
171
+ type: string;
172
+ };
173
+ minItems: number;
174
+ maxItems: number;
175
+ };
176
+ minItems: number;
177
+ maxItems: number;
178
+ };
179
+ iconLayout: {
180
+ type: string;
181
+ };
182
+ iconShape: {
183
+ type: string;
184
+ additionalProperties: boolean;
185
+ };
102
186
  preset: {
103
187
  type: string;
104
188
  };
@@ -107,6 +191,12 @@ export declare const MapBlock: {
107
191
  };
108
192
  };
109
193
  };
194
+ disableControls: {
195
+ type: string;
196
+ };
197
+ disableBalloons: {
198
+ type: string;
199
+ };
110
200
  };
111
201
  };
112
202
  description: {
@@ -16,7 +16,7 @@ function getScriptSrc(params) {
16
16
  return `${scriptSrc}?key=${apiKey}&language=${lang}${zoom ? '&zoom=' + zoom : ''}&q=${encodeURI(address)}`;
17
17
  }
18
18
  const GoogleMap = (props) => {
19
- const { address, zoom, className } = props;
19
+ const { address, zoom, className, forceAspectRatio = true } = props;
20
20
  const { apiKey, scriptSrc } = React.useContext(mapsContext_1.MapsContext);
21
21
  const { lang = uikit_1.Lang.Ru } = React.useContext(localeContext_1.LocaleContext);
22
22
  const isMobile = React.useContext(mobileContext_1.MobileContext);
@@ -24,6 +24,9 @@ const GoogleMap = (props) => {
24
24
  const ref = React.useRef(null);
25
25
  const src = React.useMemo(() => getScriptSrc({ apiKey, scriptSrc, address, lang, zoom }), [apiKey, scriptSrc, address, lang, zoom]);
26
26
  React.useEffect(() => {
27
+ if (!forceAspectRatio) {
28
+ return;
29
+ }
27
30
  const updateSize = (0, debounce_1.default)(() => {
28
31
  if (ref.current) {
29
32
  setHeight(Math.round((0, helpers_1.getMapHeight)(ref.current.offsetWidth, isMobile)));
@@ -31,10 +34,11 @@ const GoogleMap = (props) => {
31
34
  }, 100);
32
35
  updateSize();
33
36
  window.addEventListener('resize', updateSize, { passive: true });
37
+ // eslint-disable-next-line consistent-return
34
38
  return () => {
35
39
  window.removeEventListener('resize', updateSize);
36
40
  };
37
- }, [isMobile]);
41
+ }, [forceAspectRatio, isMobile]);
38
42
  if (!apiKey || !address) {
39
43
  return null;
40
44
  }
@@ -1 +1 @@
1
- {"version":3,"file":"GoogleMap.js","sourceRoot":"../../../../src","sources":["components/Map/GoogleMap.tsx"],"names":[],"mappings":";;;;AAAA,qDAA+B;AAE/B,6CAAuC;AACvC,0EAAuC;AAEvC,gFAAwE;AACxE,0EAAkE;AAClE,wEAA0D;AAE1D,gDAAkC;AAElC,0CAAuC;AAEvC,MAAM,CAAC,GAAG,IAAA,aAAK,EAAC,KAAK,CAAC,CAAC;AAUvB,SAAS,YAAY,CAAC,MAA2B;IAC7C,MAAM,EAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAC,GAAG,MAAM,CAAC;IAExD,OAAO,GAAG,SAAS,QAAQ,MAAM,aAAa,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,SAAS,CAC3F,OAAO,CACV,EAAE,CAAC;AACR,CAAC;AAED,MAAM,SAAS,GAAG,CAAC,KAAgB,EAAE,EAAE;IACnC,MAAM,EAAC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAC,GAAG,KAAK,CAAC;IACzC,MAAM,EAAC,MAAM,EAAE,SAAS,EAAC,GAAG,KAAK,CAAC,UAAU,CAAC,yBAAW,CAAC,CAAC;IAC1D,MAAM,EAAC,IAAI,GAAG,YAAI,CAAC,EAAE,EAAC,GAAG,KAAK,CAAC,UAAU,CAAC,6BAAa,CAAC,CAAC;IACzD,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAC,6BAAa,CAAC,CAAC;IAEjD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAqB,SAAS,CAAC,CAAC;IAC1E,MAAM,GAAG,GAAG,KAAK,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,kBAAe,SAAS,CAAC","sourcesContent":["import * as React from 'react';\n\nimport {Lang} from '@gravity-ui/uikit';\nimport debounce from 'lodash/debounce';\n\nimport {LocaleContext} from '../../context/localeContext/localeContext';\nimport {MapsContext} from '../../context/mapsContext/mapsContext';\nimport {MobileContext} from '../../context/mobileContext';\nimport {GMapProps} from '../../models';\nimport {block} from '../../utils';\n\nimport {getMapHeight} from './helpers';\n\nconst b = block('map');\n\ninterface GoogleMapLinkParams {\n apiKey: string;\n scriptSrc: string;\n address: string;\n lang: `${Lang}`;\n zoom?: number;\n}\n\nfunction getScriptSrc(params: GoogleMapLinkParams) {\n const {apiKey, scriptSrc, address, lang, zoom} = params;\n\n return `${scriptSrc}?key=${apiKey}&language=${lang}${zoom ? '&zoom=' + zoom : ''}&q=${encodeURI(\n address,\n )}`;\n}\n\nconst GoogleMap = (props: GMapProps) => {\n const {address, zoom, className} = props;\n const {apiKey, scriptSrc} = React.useContext(MapsContext);\n const {lang = Lang.Ru} = React.useContext(LocaleContext);\n const isMobile = React.useContext(MobileContext);\n\n const [height, setHeight] = React.useState<number | undefined>(undefined);\n const ref = React.useRef<HTMLIFrameElement>(null);\n const src = React.useMemo(\n () => getScriptSrc({apiKey, scriptSrc, address, lang, zoom}),\n [apiKey, scriptSrc, address, lang, zoom],\n );\n\n React.useEffect(() => {\n const updateSize = debounce(() => {\n if (ref.current) {\n setHeight(Math.round(getMapHeight(ref.current.offsetWidth, isMobile)));\n }\n }, 100);\n\n updateSize();\n window.addEventListener('resize', updateSize, {passive: true});\n\n return () => {\n window.removeEventListener('resize', updateSize);\n };\n }, [isMobile]);\n\n if (!apiKey || !address) {\n return null;\n }\n\n return (\n <iframe\n className={b(null, className)}\n ref={ref}\n style={{\n height,\n }}\n title=\"Google Map\"\n loading=\"lazy\"\n allowFullScreen\n referrerPolicy=\"no-referrer-when-downgrade\"\n src={src}\n />\n );\n};\n\nexport default GoogleMap;\n"]}
1
+ {"version":3,"file":"GoogleMap.js","sourceRoot":"../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';\nimport debounce from 'lodash/debounce';\n\nimport {LocaleContext} from '../../context/localeContext/localeContext';\nimport {MapsContext} from '../../context/mapsContext/mapsContext';\nimport {MobileContext} from '../../context/mobileContext';\nimport {GMapProps} from '../../models';\nimport {block} from '../../utils';\n\nimport {getMapHeight} from './helpers';\n\nconst b = block('map');\n\ninterface GoogleMapLinkParams {\n apiKey: string;\n scriptSrc: string;\n address: string;\n lang: `${Lang}`;\n zoom?: number;\n}\n\nfunction getScriptSrc(params: GoogleMapLinkParams) {\n const {apiKey, scriptSrc, address, lang, zoom} = params;\n\n return `${scriptSrc}?key=${apiKey}&language=${lang}${zoom ? '&zoom=' + zoom : ''}&q=${encodeURI(\n address,\n )}`;\n}\n\nconst GoogleMap = (props: GMapProps) => {\n const {address, zoom, className, forceAspectRatio = true} = props;\n const {apiKey, scriptSrc} = React.useContext(MapsContext);\n const {lang = Lang.Ru} = React.useContext(LocaleContext);\n const isMobile = React.useContext(MobileContext);\n\n const [height, setHeight] = React.useState<number | undefined>(undefined);\n const ref = React.useRef<HTMLIFrameElement>(null);\n const src = React.useMemo(\n () => getScriptSrc({apiKey, scriptSrc, address, lang, zoom}),\n [apiKey, scriptSrc, address, lang, zoom],\n );\n\n React.useEffect(() => {\n if (!forceAspectRatio) {\n return;\n }\n\n const updateSize = debounce(() => {\n if (ref.current) {\n setHeight(Math.round(getMapHeight(ref.current.offsetWidth, isMobile)));\n }\n }, 100);\n\n updateSize();\n window.addEventListener('resize', updateSize, {passive: true});\n\n // eslint-disable-next-line consistent-return\n return () => {\n window.removeEventListener('resize', updateSize);\n };\n }, [forceAspectRatio, isMobile]);\n\n if (!apiKey || !address) {\n return null;\n }\n\n return (\n <iframe\n className={b(null, className)}\n ref={ref}\n style={{\n height,\n }}\n title=\"Google Map\"\n loading=\"lazy\"\n allowFullScreen\n referrerPolicy=\"no-referrer-when-downgrade\"\n src={src}\n />\n );\n};\n\nexport default GoogleMap;\n"]}
@@ -1,13 +1,13 @@
1
- import { YMapMarker, YMapProps } from "../../../models/index.js";
2
- type PlacemarksProps = Pick<YMapProps, 'zoom' | 'markers'>;
1
+ import { YMapMarkerPrivate, YMapProps } from "../../../models/index.js";
2
+ type PlacemarksProps = Pick<YMapProps, 'zoom' | 'markers' | 'areaMargin'>;
3
3
  export declare class YMap {
4
4
  private ymap;
5
5
  private mapRef;
6
6
  private coords;
7
7
  constructor(ymap: Ymaps.Map, mapRef: HTMLDivElement | null);
8
8
  showPlacemarks(props: PlacemarksProps): Promise<void>;
9
- findAddress(marker: YMapMarker): Promise<void>;
10
- findCoordinate(marker: YMapMarker): void;
9
+ findAddress(marker: YMapMarkerPrivate): Promise<void>;
10
+ findCoordinate(marker: YMapMarkerPrivate): void;
11
11
  private drawPlaceMarkStyle;
12
12
  private recalcZoomAndCenter;
13
13
  private clearOldPlacemarks;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.YMap = void 0;
4
+ const utils_1 = require("./utils.js");
4
5
  var GeoObjectTypes;
5
6
  (function (GeoObjectTypes) {
6
7
  GeoObjectTypes["Properties"] = "properties";
@@ -11,9 +12,17 @@ const DEFAULT_PLACEMARKS_COLOR = '#dc534b';
11
12
  const DEFAULT_PLACEMARKS_PRESET = 'islands#dotIcon';
12
13
  const DEFAULT_MAP_CONTROL_BUTTON_HEIGHT = 30;
13
14
  const geoObjectPropsAndOptions = {
15
+ cursor: GeoObjectTypes.Options,
14
16
  iconCaption: GeoObjectTypes.Properties,
15
17
  iconContent: GeoObjectTypes.Properties,
16
18
  iconColor: GeoObjectTypes.Options,
19
+ iconImageHref: GeoObjectTypes.Options,
20
+ iconImageSize: GeoObjectTypes.Options,
21
+ iconImageOffset: GeoObjectTypes.Options,
22
+ iconImageClipRect: GeoObjectTypes.Options,
23
+ iconLayout: GeoObjectTypes.Options,
24
+ iconShape: GeoObjectTypes.Options,
25
+ interactivityModel: GeoObjectTypes.Options,
17
26
  preset: GeoObjectTypes.Options,
18
27
  };
19
28
  class YMap {
@@ -60,40 +69,62 @@ class YMap {
60
69
  if (!preset.includes('Stretchy') && !iconColor) {
61
70
  localIconColor = DEFAULT_PLACEMARKS_COLOR;
62
71
  }
63
- Object.entries({ ...marker.label, iconColor: localIconColor, preset }).forEach(([key, value]) => {
72
+ Object.entries({
73
+ ...marker.label,
74
+ iconColor: localIconColor,
75
+ preset,
76
+ }).forEach(([key, value]) => {
64
77
  const geoObjectParamType = geoObjectPropsAndOptions[key];
65
78
  if (value && geoObjectParamType) {
66
79
  geoObject[geoObjectParamType].set(key, value);
67
80
  }
68
81
  });
69
82
  }
83
+ // eslint-disable-next-line complexity
70
84
  recalcZoomAndCenter(props) {
71
85
  const coordsLength = this.coords.length;
72
- const { zoom = 0 } = props;
86
+ const { zoom = 0, areaMargin } = props;
73
87
  if (!coordsLength) {
74
88
  return;
75
89
  }
76
- let leftBottom = [Infinity, Infinity], rightTop = [-Infinity, -Infinity];
77
- this.coords.forEach((point) => {
78
- leftBottom = [Math.min(leftBottom[0], point[0]), Math.min(leftBottom[1], point[1])];
79
- rightTop = [Math.max(rightTop[0], point[0]), Math.max(rightTop[1], point[1])];
80
- });
90
+ const utils = window.ymaps.util.bounds;
91
+ const [leftTop, rightBottom] = utils.fromPoints(this.coords);
81
92
  let newMapParams = {
82
93
  zoom,
83
94
  center: [],
84
95
  };
85
- if (zoom) {
86
- // compute only the center
87
- newMapParams.center = window.ymaps.util.bounds.getCenter([leftBottom, rightTop]);
88
- }
89
- else {
90
- newMapParams = window.ymaps.util.bounds.getCenterAndZoom([leftBottom, rightTop], [this.mapRef?.clientWidth, this.mapRef?.clientHeight], undefined, { margin: DEFAULT_MAP_CONTROL_BUTTON_HEIGHT });
96
+ const parsedAreaMargin = areaMargin
97
+ ? (0, utils_1.parseMargin)(areaMargin)
98
+ : [0, 0, 0, 0];
99
+ const hasZoom = Boolean(zoom);
100
+ const hasAreaMargin = parsedAreaMargin.some(Boolean);
101
+ const containerSize = [
102
+ this.mapRef?.clientWidth ?? 0,
103
+ this.mapRef?.clientHeight ?? 0,
104
+ ];
105
+ switch (true) {
106
+ case hasAreaMargin && hasZoom:
107
+ // calculate center and zoom in accordace with current zoom and margin
108
+ newMapParams = (0, utils_1.calculateMapParamsWithMarginAndZoom)([leftTop, rightBottom], zoom, parsedAreaMargin, containerSize);
109
+ break;
110
+ case hasAreaMargin:
111
+ // calculate center and zoom with custom margin
112
+ newMapParams = utils.getCenterAndZoom([leftTop, rightBottom], containerSize, undefined, { margin: areaMargin, preciseZoom: true });
113
+ break;
114
+ case hasZoom:
115
+ // calculate only center
116
+ newMapParams.center = utils.getCenter([leftTop, rightBottom]);
117
+ break;
118
+ default:
119
+ // calculate center and zoom with default margin
120
+ newMapParams = utils.getCenterAndZoom([leftTop, rightBottom], containerSize, undefined, { margin: DEFAULT_MAP_CONTROL_BUTTON_HEIGHT });
91
121
  }
92
122
  this.ymap.setCenter(newMapParams.center);
93
123
  // Use default zoom for one placemark
94
- if (coordsLength > 1 && !zoom) {
95
- this.ymap.setZoom(newMapParams.zoom);
124
+ if (coordsLength <= 1 && !hasAreaMargin && hasZoom) {
125
+ return;
96
126
  }
127
+ this.ymap.setZoom(newMapParams.zoom);
97
128
  }
98
129
  clearOldPlacemarks() {
99
130
  if (this.coords.length === 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"YMap.js","sourceRoot":"../../../../../src","sources":["components/Map/YMap/YMap.ts"],"names":[],"mappings":";;;AAGA,IAAK,cAGJ;AAHD,WAAK,cAAc;IACf,2CAAyB,CAAA;IACzB,qCAAmB,CAAA;AACvB,CAAC,EAHI,cAAc,KAAd,cAAc,QAGlB;AAED,MAAM,wBAAwB,GAAG,SAAS,CAAC;AAC3C,mGAAmG;AACnG,MAAM,yBAAyB,GAAG,iBAAiB,CAAC;AACpD,MAAM,iCAAiC,GAAG,EAAE,CAAC;AAE7C,MAAM,wBAAwB,GAAG;IAC7B,WAAW,EAAE,cAAc,CAAC,UAAU;IACtC,WAAW,EAAE,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AE,WAAW,EAAE,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC,EACrD,SAAS,EACT,EAAC,MAAM,EAAE,iCAAiC,EAAC,CAC9C,CAAC;QACN,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAEzC,qCAAqC;QACrC,IAAI,YAAY,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YAC5B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QACzC,CAAC;IACL,CAAC;IAEO,kBAAkB;QACtB,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO;QACX,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACrB,CAAC;CACJ;AApHD,oBAoHC","sourcesContent":["import {YMapMarker, YMapMarkerLabel, YMapProps} from '../../../models';\nimport {Coordinate} from '../../../models/constructor-items/common';\n\nenum GeoObjectTypes {\n Properties = 'properties',\n Options = 'options',\n}\n\nconst DEFAULT_PLACEMARKS_COLOR = '#dc534b';\n// presetStorage: https://yandex.com/dev/maps/jsapi/doc/2.1/ref/reference/option.presetStorage.html\nconst DEFAULT_PLACEMARKS_PRESET = 'islands#dotIcon';\nconst DEFAULT_MAP_CONTROL_BUTTON_HEIGHT = 30;\n\nconst geoObjectPropsAndOptions = {\n iconCaption: GeoObjectTypes.Properties,\n iconContent: GeoObjectTypes.Properties,\n iconColor: GeoObjectTypes.Options,\n preset: GeoObjectTypes.Options,\n};\n\ntype PlacemarksProps = Pick<YMapProps, 'zoom' | 'markers'>;\n\nexport class YMap {\n private ymap: Ymaps.Map;\n private mapRef: HTMLDivElement | null;\n private coords: Coordinate[] = [];\n\n constructor(ymap: Ymaps.Map, mapRef: HTMLDivElement | null) {\n this.ymap = ymap;\n this.mapRef = mapRef;\n }\n\n async showPlacemarks(props: PlacemarksProps) {\n this.clearOldPlacemarks();\n\n for (const marker of props.markers) {\n if (marker.address) {\n await this.findAddress(marker);\n } else if (marker.coordinate) {\n this.findCoordinate(marker);\n }\n }\n\n this.recalcZoomAndCenter(props);\n }\n\n async findAddress(marker: YMapMarker) {\n try {\n const res = await window.ymaps.geocode(marker.address, {results: 1});\n const geoObject = res.geoObjects.get(0);\n const coordinate = geoObject.geometry.getCoordinates();\n\n this.coords.push(coordinate);\n\n this.drawPlaceMarkStyle(geoObject, marker);\n\n this.ymap.geoObjects.add(geoObject);\n } catch {} // If error - placemark will not be displayed\n }\n\n findCoordinate(marker: YMapMarker) {\n const geoObject = new window.ymaps.Placemark(marker.coordinate, {});\n\n this.coords.push(marker.coordinate as Coordinate);\n this.drawPlaceMarkStyle(geoObject, marker);\n this.ymap.geoObjects.add(geoObject);\n }\n\n private drawPlaceMarkStyle(geoObject: Ymaps.GeoObject, marker: YMapMarker) {\n const {iconColor, preset = DEFAULT_PLACEMARKS_PRESET} = marker.label || {};\n let localIconColor: string | undefined = iconColor;\n\n // You can set the preset option together with the iconColor option only if it not a 'Stretchy' preset\n if (!preset.includes('Stretchy') && !iconColor) {\n localIconColor = DEFAULT_PLACEMARKS_COLOR;\n }\n\n Object.entries({...marker.label, iconColor: localIconColor, preset}).forEach(\n ([key, value]) => {\n const geoObjectParamType: GeoObjectTypes | undefined =\n geoObjectPropsAndOptions[key as keyof YMapMarkerLabel];\n\n if (value && geoObjectParamType) {\n geoObject[geoObjectParamType].set(key, value);\n }\n },\n );\n }\n\n private recalcZoomAndCenter(props: PlacemarksProps) {\n const coordsLength = this.coords.length;\n const {zoom = 0} = props;\n\n if (!coordsLength) {\n return;\n }\n\n let leftBottom = [Infinity, Infinity],\n rightTop = [-Infinity, -Infinity];\n\n this.coords.forEach((point) => {\n leftBottom = [Math.min(leftBottom[0], point[0]), Math.min(leftBottom[1], point[1])];\n rightTop = [Math.max(rightTop[0], point[0]), Math.max(rightTop[1], point[1])];\n });\n\n let newMapParams = {\n zoom,\n center: [],\n };\n\n if (zoom) {\n // compute only the center\n newMapParams.center = window.ymaps.util.bounds.getCenter([leftBottom, rightTop]);\n } else {\n newMapParams = window.ymaps.util.bounds.getCenterAndZoom(\n [leftBottom, rightTop],\n [this.mapRef?.clientWidth, this.mapRef?.clientHeight],\n undefined,\n {margin: DEFAULT_MAP_CONTROL_BUTTON_HEIGHT},\n );\n }\n\n this.ymap.setCenter(newMapParams.center);\n\n // Use default zoom for one placemark\n if (coordsLength > 1 && !zoom) {\n this.ymap.setZoom(newMapParams.zoom);\n }\n }\n\n private clearOldPlacemarks() {\n if (this.coords.length === 0) {\n return;\n }\n\n this.ymap.geoObjects.removeAll();\n this.coords = [];\n }\n}\n"]}
1
+ {"version":3,"file":"YMap.js","sourceRoot":"../../../../../src","sources":["components/Map/YMap/YMap.ts"],"names":[],"mappings":";;;AAGA,sCAAuF;AAEvF,IAAK,cAGJ;AAHD,WAAK,cAAc;IACf,2CAAyB,CAAA;IACzB,qCAAmB,CAAA;AACvB,CAAC,EAHI,cAAc,KAAd,cAAc,QAGlB;AAED,MAAM,wBAAwB,GAAG,SAAS,CAAC;AAC3C,mGAAmG;AACnG,MAAM,yBAAyB,GAAG,iBAAiB,CAAC;AACpD,MAAM,iCAAiC,GAAG,EAAE,CAAC;AAE7C,MAAM,wBAAwB,GAAyD;IACnF,MAAM,EAAE,cAAc,CAAC,OAAO;IAC9B,WAAW,EAAE,cAAc,CAAC,UAAU;IACtC,WAAW,EAAE,cAAc,CAAC,UAAU;IACtC,SAAS,EAAE,cAAc,CAAC,OAAO;IACjC,aAAa,EAAE,cAAc,CAAC,OAAO;IACrC,aAAa,EAAE,cAAc,CAAC,OAAO;IACrC,eAAe,EAAE,cAAc,CAAC,OAAO;IACvC,iBAAiB,EAAE,cAAc,CAAC,OAAO;IACzC,UAAU,EAAE,cAAc,CAAC,OAAO;IAClC,SAAS,EAAE,cAAc,CAAC,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W,EAAE,IAAI,EAAC,CAC1C,CAAC;gBACF,MAAM;YACV,KAAK,OAAO;gBACR,wBAAwB;gBACxB,YAAY,CAAC,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC;gBAC9D,MAAM;YACV;gBACI,gDAAgD;gBAChD,YAAY,GAAG,KAAK,CAAC,gBAAgB,CACjC,CAAC,OAAO,EAAE,WAAW,CAAC,EACtB,aAAa,EACb,SAAS,EACT,EAAC,MAAM,EAAE,iCAAiC,EAAC,CAC9C,CAAC;QACV,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAEzC,qCAAqC;QACrC,IAAI,YAAY,IAAI,CAAC,IAAI,CAAC,aAAa,IAAI,OAAO,EAAE,CAAC;YACjD,OAAO;QACX,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC;IAEO,kBAAkB;QACtB,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO;QACX,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACrB,CAAC;CACJ;AArJD,oBAqJC","sourcesContent":["import {YMapMarkerLabelPrivate, YMapMarkerPrivate, YMapProps} from '../../../models';\nimport {Coordinate} from '../../../models/constructor-items/common';\n\nimport {ParsedMargin, calculateMapParamsWithMarginAndZoom, parseMargin} from './utils';\n\nenum GeoObjectTypes {\n Properties = 'properties',\n Options = 'options',\n}\n\nconst DEFAULT_PLACEMARKS_COLOR = '#dc534b';\n// presetStorage: https://yandex.com/dev/maps/jsapi/doc/2.1/ref/reference/option.presetStorage.html\nconst DEFAULT_PLACEMARKS_PRESET = 'islands#dotIcon';\nconst DEFAULT_MAP_CONTROL_BUTTON_HEIGHT = 30;\n\nconst geoObjectPropsAndOptions: Record<keyof YMapMarkerLabelPrivate, GeoObjectTypes> = {\n cursor: GeoObjectTypes.Options,\n iconCaption: GeoObjectTypes.Properties,\n iconContent: GeoObjectTypes.Properties,\n iconColor: GeoObjectTypes.Options,\n iconImageHref: GeoObjectTypes.Options,\n iconImageSize: GeoObjectTypes.Options,\n iconImageOffset: GeoObjectTypes.Options,\n iconImageClipRect: GeoObjectTypes.Options,\n iconLayout: GeoObjectTypes.Options,\n iconShape: GeoObjectTypes.Options,\n interactivityModel: GeoObjectTypes.Options,\n preset: GeoObjectTypes.Options,\n};\n\ntype PlacemarksProps = Pick<YMapProps, 'zoom' | 'markers' | 'areaMargin'>;\n\nexport class YMap {\n private ymap: Ymaps.Map;\n private mapRef: HTMLDivElement | null;\n private coords: Coordinate[] = [];\n\n constructor(ymap: Ymaps.Map, mapRef: HTMLDivElement | null) {\n this.ymap = ymap;\n this.mapRef = mapRef;\n }\n\n async showPlacemarks(props: PlacemarksProps) {\n this.clearOldPlacemarks();\n\n for (const marker of props.markers) {\n if (marker.address) {\n await this.findAddress(marker);\n } else if (marker.coordinate) {\n this.findCoordinate(marker);\n }\n }\n\n this.recalcZoomAndCenter(props);\n }\n\n async findAddress(marker: YMapMarkerPrivate) {\n try {\n const res = await window.ymaps.geocode(marker.address, {results: 1});\n const geoObject = res.geoObjects.get(0);\n const coordinate = geoObject.geometry.getCoordinates();\n\n this.coords.push(coordinate);\n\n this.drawPlaceMarkStyle(geoObject, marker);\n\n this.ymap.geoObjects.add(geoObject);\n } catch {} // If error - placemark will not be displayed\n }\n\n findCoordinate(marker: YMapMarkerPrivate) {\n const geoObject = new window.ymaps.Placemark(marker.coordinate, {});\n\n this.coords.push(marker.coordinate as Coordinate);\n this.drawPlaceMarkStyle(geoObject, marker);\n this.ymap.geoObjects.add(geoObject);\n }\n\n private drawPlaceMarkStyle(geoObject: Ymaps.GeoObject, marker: YMapMarkerPrivate) {\n const {iconColor, preset = DEFAULT_PLACEMARKS_PRESET} = marker.label || {};\n let localIconColor: string | undefined = iconColor;\n\n // You can set the preset option together with the iconColor option only if it not a 'Stretchy' preset\n if (!preset.includes('Stretchy') && !iconColor) {\n localIconColor = DEFAULT_PLACEMARKS_COLOR;\n }\n\n Object.entries({\n ...marker.label,\n iconColor: localIconColor,\n preset,\n }).forEach(([key, value]) => {\n const geoObjectParamType: GeoObjectTypes | undefined =\n geoObjectPropsAndOptions[key as keyof YMapMarkerLabelPrivate];\n\n if (value && geoObjectParamType) {\n geoObject[geoObjectParamType].set(key, value);\n }\n });\n }\n\n // eslint-disable-next-line complexity\n private recalcZoomAndCenter(props: PlacemarksProps) {\n const coordsLength = this.coords.length;\n const {zoom = 0, areaMargin} = props;\n\n if (!coordsLength) {\n return;\n }\n\n const utils = window.ymaps.util.bounds;\n\n const [leftTop, rightBottom] = utils.fromPoints(this.coords);\n\n let newMapParams = {\n zoom,\n center: [],\n };\n\n const parsedAreaMargin = areaMargin\n ? parseMargin(areaMargin)\n : ([0, 0, 0, 0] as ParsedMargin);\n\n const hasZoom = Boolean(zoom);\n const hasAreaMargin = parsedAreaMargin.some(Boolean);\n const containerSize = [\n this.mapRef?.clientWidth ?? 0,\n this.mapRef?.clientHeight ?? 0,\n ] as Coordinate;\n\n switch (true) {\n case hasAreaMargin && hasZoom:\n // calculate center and zoom in accordace with current zoom and margin\n newMapParams = calculateMapParamsWithMarginAndZoom(\n [leftTop, rightBottom],\n zoom,\n parsedAreaMargin,\n containerSize,\n );\n break;\n case hasAreaMargin:\n // calculate center and zoom with custom margin\n newMapParams = utils.getCenterAndZoom(\n [leftTop, rightBottom],\n containerSize,\n undefined,\n {margin: areaMargin, preciseZoom: true},\n );\n break;\n case hasZoom:\n // calculate only center\n newMapParams.center = utils.getCenter([leftTop, rightBottom]);\n break;\n default:\n // calculate center and zoom with default margin\n newMapParams = utils.getCenterAndZoom(\n [leftTop, rightBottom],\n containerSize,\n undefined,\n {margin: DEFAULT_MAP_CONTROL_BUTTON_HEIGHT},\n );\n }\n\n this.ymap.setCenter(newMapParams.center);\n\n // Use default zoom for one placemark\n if (coordsLength <= 1 && !hasAreaMargin && hasZoom) {\n return;\n }\n\n this.ymap.setZoom(newMapParams.zoom);\n }\n\n private clearOldPlacemarks() {\n if (this.coords.length === 0) {\n return;\n }\n\n this.ymap.geoObjects.removeAll();\n this.coords = [];\n }\n}\n"]}
@@ -21,8 +21,12 @@ const DEFAULT_ZOOM = 9;
21
21
  // We use this init center to create a map
22
22
  // The real center of the map will be calculated later, using the coordinates of the markers
23
23
  const INITIAL_CENTER = [0, 0];
24
+ const BALLOON_DISABLING_MARKER_OPTIONS = {
25
+ cursor: 'drag',
26
+ interactivityModel: 'default#silent',
27
+ };
24
28
  const YandexMap = (props) => {
25
- const { markers, zoom, id, className } = props;
29
+ const { markers, zoom, id, disableControls = false, disableBalloons = false, areaMargin, className, forceAspectRatio = true, } = props;
26
30
  const { apiKey, scriptSrc, nonce } = React.useContext(mapsContext_1.MapsContext);
27
31
  const isMobile = React.useContext(mobileContext_1.MobileContext);
28
32
  const { lang = 'ru' } = React.useContext(localeContext_1.LocaleContext);
@@ -44,12 +48,30 @@ const YandexMap = (props) => {
44
48
  setYmaps(new YMap_1.YMap(new window.ymaps.Map(containerId, {
45
49
  center: INITIAL_CENTER,
46
50
  zoom: zoom || DEFAULT_ZOOM,
47
- }, { autoFitToViewport: 'always' }), ref.current));
51
+ controls: disableControls ? [] : undefined,
52
+ }, {
53
+ autoFitToViewport: 'always',
54
+ suppressMapOpenBlock: disableControls,
55
+ yandexMapDisablePoiInteractivity: disableControls,
56
+ }), ref.current));
48
57
  });
49
58
  setLoading(false);
50
59
  })();
51
- }, [apiKey, lang, scriptSrc, containerId, zoom, nonce, attemptsIndex, setLoading]);
60
+ }, [
61
+ apiKey,
62
+ lang,
63
+ scriptSrc,
64
+ containerId,
65
+ zoom,
66
+ nonce,
67
+ attemptsIndex,
68
+ setLoading,
69
+ disableControls,
70
+ ]);
52
71
  React.useEffect(() => {
72
+ if (!forceAspectRatio) {
73
+ return;
74
+ }
53
75
  const updateSize = (0, debounce_1.default)(() => {
54
76
  if (ref.current) {
55
77
  setHeight(Math.round((0, helpers_1.getMapHeight)(ref.current.offsetWidth, isMobile)));
@@ -57,20 +79,27 @@ const YandexMap = (props) => {
57
79
  }, 100);
58
80
  updateSize();
59
81
  window.addEventListener('resize', updateSize, { passive: true });
82
+ // eslint-disable-next-line consistent-return
60
83
  return () => {
61
84
  window.removeEventListener('resize', updateSize);
62
85
  };
63
- }, [markers, ymap, setYmaps, isMobile]);
86
+ }, [isMobile, forceAspectRatio]);
64
87
  React.useEffect(() => {
65
88
  if (ymap) {
66
89
  // show with computed center and placemarks
67
90
  const showPlacemarks = async () => {
68
- await ymap.showPlacemarks({ markers, zoom });
91
+ const privateMarkers = disableBalloons
92
+ ? markers.map(({ label, ...marker }) => ({
93
+ ...marker,
94
+ label: { ...label, ...BALLOON_DISABLING_MARKER_OPTIONS },
95
+ }))
96
+ : markers;
97
+ await ymap.showPlacemarks({ markers: privateMarkers, zoom, areaMargin });
69
98
  setReady(true);
70
99
  };
71
100
  showPlacemarks();
72
101
  }
73
- });
102
+ }, [ymap, markers, zoom, disableBalloons, areaMargin]);
74
103
  if (!markers)
75
104
  return null;
76
105
  return ((0, jsx_runtime_1.jsx)(ErrorWrapper_1.default, { isError: YandexMapApiLoader_1.YMapsApiLoader.status === YandexMapApiLoader_1.MapApiStatus.Error, text: (0, i18n_1.i18n)('map-load-error'), buttonText: (0, i18n_1.i18n)('map-try-again'), handler: onTryAgain, className: b('wrapper'), children: (0, jsx_runtime_1.jsxs)("div", { className: b('wrapper'), children: [(0, jsx_runtime_1.jsx)("div", { id: containerId, className: b({ hidden: !ready }, className), ref: ref, style: { height } }), loading ? (0, jsx_runtime_1.jsx)(uikit_1.Spin, { size: "xl", className: b('spinner') }) : null] }) }));
@@ -1 +1 @@
1
- {"version":3,"file":"YandexMap.js","sourceRoot":"../../../../../src","s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AAE,CAAC,CAAC,EAAC,MAAM,EAAE,CAAC,KAAK,EAAC,EAAE,SAAS,CAAC,EACzC,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,EAAC,MAAM,EAAC,GACjB,EACD,OAAO,CAAC,CAAC,CAAC,uBAAC,YAAI,IAAC,IAAI,EAAC,IAAI,EAAC,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,GAAI,CAAC,CAAC,CAAC,IAAI,IAC3D,GACK,CAClB,CAAC;AACN,CAAC,CAAC;AAEF,kBAAe,SAAS,CAAC","sourcesContent":["import * as React from 'react';\n\nimport {Spin} from '@gravity-ui/uikit';\nimport debounce from 'lodash/debounce';\n\nimport {LocaleContext} from '../../../context/localeContext/localeContext';\nimport {MapsContext} from '../../../context/mapsContext/mapsContext';\nimport {MobileContext} from '../../../context/mobileContext';\nimport {YMapProps} from '../../../models';\nimport {block} from '../../../utils';\nimport ErrorWrapper from '../../ErrorWrapper/ErrorWrapper';\nimport {getMapHeight} from '../helpers';\n\nimport {YMap} from './YMap';\nimport {MapApiStatus, YMapsApiLoader} from './YandexMapApiLoader';\nimport {i18n} from './i18n';\n\nconst b = block('map');\nconst DEFAULT_CONTAINER_ID = 'ymap';\nconst DEFAULT_ZOOM = 9;\n// Center - is a required parameter for creating a new map\n// We use this init center to create a map\n// The real center of the map will be calculated later, using the coordinates of the markers\nconst INITIAL_CENTER = [0, 0];\n\nconst YandexMap = (props: YMapProps) => {\n const {markers, zoom, id, className} = props;\n const {apiKey, scriptSrc, nonce} = React.useContext(MapsContext);\n const isMobile = React.useContext(MobileContext);\n\n const {lang = 'ru'} = React.useContext(LocaleContext);\n const containerId = `${DEFAULT_CONTAINER_ID}-${id}`;\n\n const [ymap, setYmaps] = React.useState<YMap | null>(null);\n const [height, setHeight] = React.useState<number | undefined>(undefined);\n const ref = React.useRef<HTMLDivElement>(null);\n\n const [loading, setLoading] = React.useState<boolean>(false);\n const [ready, setReady] = React.useState<boolean>(false);\n const [attemptsIndex, setAttemptsIndex] = React.useState<number>(0);\n const onTryAgain = React.useCallback(() => {\n setAttemptsIndex(attemptsIndex + 1);\n }, [attemptsIndex]);\n\n React.useEffect(() => {\n (async function () {\n setLoading(true);\n\n await YMapsApiLoader.loadApi(apiKey, scriptSrc, lang, nonce);\n\n window.ymaps?.ready(() => {\n setYmaps(\n new YMap(\n new window.ymaps.Map(\n containerId,\n {\n center: INITIAL_CENTER,\n zoom: zoom || DEFAULT_ZOOM,\n },\n {autoFitToViewport: 'always'},\n ),\n ref.current,\n ),\n );\n });\n\n setLoading(false);\n })();\n }, [apiKey, lang, scriptSrc, containerId, zoom, nonce, attemptsIndex, setLoading]);\n\n React.useEffect(() => {\n const updateSize = debounce(() => {\n if (ref.current) {\n setHeight(Math.round(getMapHeight(ref.current.offsetWidth, isMobile)));\n }\n }, 100);\n\n updateSize();\n window.addEventListener('resize', updateSize, {passive: true});\n\n return () => {\n window.removeEventListener('resize', updateSize);\n };\n }, [markers, ymap, setYmaps, isMobile]);\n\n React.useEffect(() => {\n if (ymap) {\n // show with computed center and placemarks\n const showPlacemarks = async () => {\n await ymap.showPlacemarks({markers, zoom});\n\n setReady(true);\n };\n\n showPlacemarks();\n }\n });\n\n if (!markers) return null;\n\n return (\n <ErrorWrapper\n isError={YMapsApiLoader.status === MapApiStatus.Error}\n text={i18n('map-load-error')}\n buttonText={i18n('map-try-again')}\n handler={onTryAgain}\n className={b('wrapper')}\n >\n <div className={b('wrapper')}>\n {/* hidden - to show the map after calculating the center */}\n <div\n id={containerId}\n className={b({hidden: !ready}, className)}\n ref={ref}\n style={{height}}\n />\n {loading ? <Spin size=\"xl\" className={b('spinner')} /> : null}\n </div>\n </ErrorWrapper>\n );\n};\n\nexport default YandexMap;\n"]}
1
+ {"version":3,"file":"YandexMap.js","sourceRoot":"../../../../../src","sources":["components/Map/YMap/YandexMap.tsx"],"names":[],"mappings":";;;;AAAA,qDAA+B;AAE/B,6CAAuC;AACvC,0EAAuC;AAEvC,mFAA2E;AAC3E,6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AAE,UAAU,EAAC,CAAC,CAAC;gBAEvE,QAAQ,CAAC,IAAI,CAAC,CAAC;YACnB,CAAC,CAAC;YAEF,cAAc,EAAE,CAAC;QACrB,CAAC;IACL,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,UAAU,CAAC,CAAC,CAAC;IAEvD,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;IAE1B,OAAO,CACH,uBAAC,sBAAY,IACT,OAAO,EAAE,mCAAc,CAAC,MAAM,KAAK,iCAAY,CAAC,KAAK,EACrD,IAAI,EAAE,IAAA,WAAI,EAAC,gBAAgB,CAAC,EAC5B,UAAU,EAAE,IAAA,WAAI,EAAC,eAAe,CAAC,EACjC,OAAO,EAAE,UAAU,EACnB,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,YAEvB,iCAAK,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,aAExB,gCACI,EAAE,EAAE,WAAW,EACf,SAAS,EAAE,CAAC,CAAC,EAAC,MAAM,EAAE,CAAC,KAAK,EAAC,EAAE,SAAS,CAAC,EACzC,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,EAAC,MAAM,EAAC,GACjB,EACD,OAAO,CAAC,CAAC,CAAC,uBAAC,YAAI,IAAC,IAAI,EAAC,IAAI,EAAC,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,GAAI,CAAC,CAAC,CAAC,IAAI,IAC3D,GACK,CAClB,CAAC;AACN,CAAC,CAAC;AAEF,kBAAe,SAAS,CAAC","sourcesContent":["import * as React from 'react';\n\nimport {Spin} from '@gravity-ui/uikit';\nimport debounce from 'lodash/debounce';\n\nimport {LocaleContext} from '../../../context/localeContext/localeContext';\nimport {MapsContext} from '../../../context/mapsContext/mapsContext';\nimport {MobileContext} from '../../../context/mobileContext';\nimport {YMapMarkerLabelPrivate, YMapMarkerPrivate, YMapProps} from '../../../models';\nimport {block} from '../../../utils';\nimport ErrorWrapper from '../../ErrorWrapper/ErrorWrapper';\nimport {getMapHeight} from '../helpers';\n\nimport {YMap} from './YMap';\nimport {MapApiStatus, YMapsApiLoader} from './YandexMapApiLoader';\nimport {i18n} from './i18n';\n\nconst b = block('map');\nconst DEFAULT_CONTAINER_ID = 'ymap';\nconst DEFAULT_ZOOM = 9;\n// Center - is a required parameter for creating a new map\n// We use this init center to create a map\n// The real center of the map will be calculated later, using the coordinates of the markers\nconst INITIAL_CENTER = [0, 0];\n\nconst BALLOON_DISABLING_MARKER_OPTIONS: YMapMarkerLabelPrivate = {\n cursor: 'drag',\n interactivityModel: 'default#silent',\n};\n\nconst YandexMap = (props: YMapProps) => {\n const {\n markers,\n zoom,\n id,\n disableControls = false,\n disableBalloons = false,\n areaMargin,\n className,\n forceAspectRatio = true,\n } = props;\n const {apiKey, scriptSrc, nonce} = React.useContext(MapsContext);\n const isMobile = React.useContext(MobileContext);\n\n const {lang = 'ru'} = React.useContext(LocaleContext);\n const containerId = `${DEFAULT_CONTAINER_ID}-${id}`;\n\n const [ymap, setYmaps] = React.useState<YMap | null>(null);\n const [height, setHeight] = React.useState<number | undefined>(undefined);\n const ref = React.useRef<HTMLDivElement>(null);\n\n const [loading, setLoading] = React.useState<boolean>(false);\n const [ready, setReady] = React.useState<boolean>(false);\n const [attemptsIndex, setAttemptsIndex] = React.useState<number>(0);\n const onTryAgain = React.useCallback(() => {\n setAttemptsIndex(attemptsIndex + 1);\n }, [attemptsIndex]);\n\n React.useEffect(() => {\n (async function () {\n setLoading(true);\n\n await YMapsApiLoader.loadApi(apiKey, scriptSrc, lang, nonce);\n\n window.ymaps?.ready(() => {\n setYmaps(\n new YMap(\n new window.ymaps.Map(\n containerId,\n {\n center: INITIAL_CENTER,\n zoom: zoom || DEFAULT_ZOOM,\n controls: disableControls ? [] : undefined,\n },\n {\n autoFitToViewport: 'always',\n suppressMapOpenBlock: disableControls,\n yandexMapDisablePoiInteractivity: disableControls,\n },\n ),\n ref.current,\n ),\n );\n });\n\n setLoading(false);\n })();\n }, [\n apiKey,\n lang,\n scriptSrc,\n containerId,\n zoom,\n nonce,\n attemptsIndex,\n setLoading,\n disableControls,\n ]);\n\n React.useEffect(() => {\n if (!forceAspectRatio) {\n return;\n }\n\n const updateSize = debounce(() => {\n if (ref.current) {\n setHeight(Math.round(getMapHeight(ref.current.offsetWidth, isMobile)));\n }\n }, 100);\n\n updateSize();\n window.addEventListener('resize', updateSize, {passive: true});\n\n // eslint-disable-next-line consistent-return\n return () => {\n window.removeEventListener('resize', updateSize);\n };\n }, [isMobile, forceAspectRatio]);\n\n React.useEffect(() => {\n if (ymap) {\n // show with computed center and placemarks\n const showPlacemarks = async () => {\n const privateMarkers: YMapMarkerPrivate[] = disableBalloons\n ? markers.map(({label, ...marker}) => ({\n ...marker,\n label: {...label, ...BALLOON_DISABLING_MARKER_OPTIONS},\n }))\n : markers;\n\n await ymap.showPlacemarks({markers: privateMarkers, zoom, areaMargin});\n\n setReady(true);\n };\n\n showPlacemarks();\n }\n }, [ymap, markers, zoom, disableBalloons, areaMargin]);\n\n if (!markers) return null;\n\n return (\n <ErrorWrapper\n isError={YMapsApiLoader.status === MapApiStatus.Error}\n text={i18n('map-load-error')}\n buttonText={i18n('map-try-again')}\n handler={onTryAgain}\n className={b('wrapper')}\n >\n <div className={b('wrapper')}>\n {/* hidden - to show the map after calculating the center */}\n <div\n id={containerId}\n className={b({hidden: !ready}, className)}\n ref={ref}\n style={{height}}\n />\n {loading ? <Spin size=\"xl\" className={b('spinner')} /> : null}\n </div>\n </ErrorWrapper>\n );\n};\n\nexport default YandexMap;\n"]}
@@ -0,0 +1,8 @@
1
+ import { Coordinate, YMapMargin } from "../../../models/index.js";
2
+ export type ParsedMargin = [top: number, right: number, bottom: number, left: number];
3
+ export declare const parseMargin: (margin: YMapMargin) => ParsedMargin;
4
+ export declare const calcPixelBounds: ([leftTop, rightBottom]: [Coordinate, Coordinate], zoom: number, containerSize: Coordinate) => number[][];
5
+ export declare const calculateMapParamsWithMarginAndZoom: ([leftTop, rightBottom]: [Coordinate, Coordinate], zoom: number, areaMargin: ParsedMargin, containerSize: Coordinate) => {
6
+ center: any;
7
+ zoom: number;
8
+ };
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculateMapParamsWithMarginAndZoom = exports.calcPixelBounds = exports.parseMargin = void 0;
4
+ const parseMargin = (margin) => {
5
+ if (!Array.isArray(margin)) {
6
+ return [margin, margin, margin, margin];
7
+ }
8
+ if (margin.length === 2) {
9
+ return [margin[0], margin[1], margin[0], margin[1]];
10
+ }
11
+ return margin;
12
+ };
13
+ exports.parseMargin = parseMargin;
14
+ const calcPixelBounds = ([leftTop, rightBottom], zoom, containerSize) => {
15
+ const utils = window.ymaps.util.bounds;
16
+ let [[leftPx, topPx], [rightPx, bottomPx]] = utils.toGlobalPixelBounds([leftTop, rightBottom], zoom);
17
+ // fall back to container size in case there is only one marker and area is 0
18
+ if (rightPx - leftPx <= 0) {
19
+ const halfX = containerSize[0] / 2;
20
+ leftPx -= halfX;
21
+ rightPx += halfX;
22
+ }
23
+ if (bottomPx - topPx <= 0) {
24
+ const halfY = containerSize[1] / 2;
25
+ topPx -= halfY;
26
+ bottomPx += halfY;
27
+ }
28
+ return [
29
+ [leftPx, topPx],
30
+ [rightPx, bottomPx],
31
+ ];
32
+ };
33
+ exports.calcPixelBounds = calcPixelBounds;
34
+ const calcNewZoom = (l, zoom, marginSum) => {
35
+ return Math.log2((Math.pow(2, zoom) * (l - marginSum)) / l);
36
+ };
37
+ const calculateMapParamsWithMarginAndZoom = ([leftTop, rightBottom], zoom, areaMargin, containerSize) => {
38
+ const utils = window.ymaps.util.bounds;
39
+ // calculate pixel bounds with current zoom
40
+ let [[leftPx, topPx], [rightPx, bottomPx]] = (0, exports.calcPixelBounds)([leftTop, rightBottom], zoom, containerSize);
41
+ const [topMargin, rightMargin, bottomMargin, leftMargin] = areaMargin;
42
+ let zoomV;
43
+ let zoomH;
44
+ // calculate new zoom value after margins are applied
45
+ if (leftMargin && rightMargin) {
46
+ zoomH = calcNewZoom(rightPx - leftPx, zoom, leftMargin + rightMargin);
47
+ }
48
+ else {
49
+ zoomH = zoom;
50
+ }
51
+ if (topMargin && bottomMargin) {
52
+ zoomV = calcNewZoom(bottomPx - topPx, zoom, topMargin + bottomMargin);
53
+ }
54
+ else {
55
+ zoomV = zoom;
56
+ }
57
+ const newZoom = Math.min(zoomV, zoomH);
58
+ // calculate pixel bounds with new zoom
59
+ [[leftPx, topPx], [rightPx, bottomPx]] = (0, exports.calcPixelBounds)([leftTop, rightBottom], newZoom, containerSize);
60
+ // calculate new bounds (scale if both size are present, otherwise shift the map)
61
+ if (leftMargin && rightMargin) {
62
+ leftPx -= leftMargin;
63
+ rightPx += rightMargin;
64
+ }
65
+ else if (leftMargin) {
66
+ leftPx -= leftMargin;
67
+ rightPx -= leftMargin;
68
+ }
69
+ else if (rightMargin) {
70
+ leftPx += rightMargin;
71
+ rightPx += rightMargin;
72
+ }
73
+ if (topMargin && bottomMargin) {
74
+ topPx -= topMargin;
75
+ bottomPx += bottomMargin;
76
+ }
77
+ else if (topMargin) {
78
+ topPx -= topMargin;
79
+ bottomPx -= topMargin;
80
+ }
81
+ else if (bottomMargin) {
82
+ topPx += bottomMargin;
83
+ bottomPx += bottomMargin;
84
+ }
85
+ // transform new bounds into coordinates
86
+ const [newLeftTop, newRightBottom] = utils.fromGlobalPixelBounds([
87
+ [leftPx, topPx],
88
+ [rightPx, bottomPx],
89
+ ], newZoom);
90
+ return {
91
+ center: utils.getCenter([newLeftTop, newRightBottom]),
92
+ zoom: newZoom,
93
+ };
94
+ };
95
+ exports.calculateMapParamsWithMarginAndZoom = calculateMapParamsWithMarginAndZoom;
96
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"../../../../../src","sources":["components/Map/YMap/utils.ts"],"names":[],"mappings":";;;AAIO,MAAM,WAAW,GAAG,CAAC,MAAkB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AAS,CAAC,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;QACrD,IAAI,EAAE,OAAO;KAChB,CAAC;AACN,CAAC,CAAC;AA9EW,QAAA,mCAAmC,uCA8E9C","sourcesContent":["import {Coordinate, YMapMargin} from '../../../models';\n\nexport type ParsedMargin = [top: number, right: number, bottom: number, left: number];\n\nexport const parseMargin = (margin: YMapMargin): ParsedMargin => {\n if (!Array.isArray(margin)) {\n return [margin, margin, margin, margin];\n }\n\n if (margin.length === 2) {\n return [margin[0], margin[1], margin[0], margin[1]];\n }\n\n return margin;\n};\n\nexport const calcPixelBounds = (\n [leftTop, rightBottom]: [Coordinate, Coordinate],\n zoom: number,\n containerSize: Coordinate,\n) => {\n const utils = window.ymaps.util.bounds;\n\n let [[leftPx, topPx], [rightPx, bottomPx]] = utils.toGlobalPixelBounds(\n [leftTop, rightBottom],\n zoom,\n ) as [Coordinate, Coordinate];\n\n // fall back to container size in case there is only one marker and area is 0\n if (rightPx - leftPx <= 0) {\n const halfX = containerSize[0] / 2;\n leftPx -= halfX;\n rightPx += halfX;\n }\n\n if (bottomPx - topPx <= 0) {\n const halfY = containerSize[1] / 2;\n topPx -= halfY;\n bottomPx += halfY;\n }\n\n return [\n [leftPx, topPx],\n [rightPx, bottomPx],\n ];\n};\n\nconst calcNewZoom = (l: number, zoom: number, marginSum: number) => {\n return Math.log2((Math.pow(2, zoom) * (l - marginSum)) / l);\n};\n\nexport const calculateMapParamsWithMarginAndZoom = (\n [leftTop, rightBottom]: [Coordinate, Coordinate],\n zoom: number,\n areaMargin: ParsedMargin,\n containerSize: Coordinate,\n) => {\n const utils = window.ymaps.util.bounds;\n\n // calculate pixel bounds with current zoom\n let [[leftPx, topPx], [rightPx, bottomPx]] = calcPixelBounds(\n [leftTop, rightBottom],\n zoom,\n containerSize,\n );\n\n const [topMargin, rightMargin, bottomMargin, leftMargin] = areaMargin;\n\n let zoomV: number;\n let zoomH: number;\n\n // calculate new zoom value after margins are applied\n if (leftMargin && rightMargin) {\n zoomH = calcNewZoom(rightPx - leftPx, zoom, leftMargin + rightMargin);\n } else {\n zoomH = zoom;\n }\n\n if (topMargin && bottomMargin) {\n zoomV = calcNewZoom(bottomPx - topPx, zoom, topMargin + bottomMargin);\n } else {\n zoomV = zoom;\n }\n\n const newZoom = Math.min(zoomV, zoomH);\n\n // calculate pixel bounds with new zoom\n [[leftPx, topPx], [rightPx, bottomPx]] = calcPixelBounds(\n [leftTop, rightBottom],\n newZoom,\n containerSize,\n );\n\n // calculate new bounds (scale if both size are present, otherwise shift the map)\n if (leftMargin && rightMargin) {\n leftPx -= leftMargin;\n rightPx += rightMargin;\n } else if (leftMargin) {\n leftPx -= leftMargin;\n rightPx -= leftMargin;\n } else if (rightMargin) {\n leftPx += rightMargin;\n rightPx += rightMargin;\n }\n\n if (topMargin && bottomMargin) {\n topPx -= topMargin;\n bottomPx += bottomMargin;\n } else if (topMargin) {\n topPx -= topMargin;\n bottomPx -= topMargin;\n } else if (bottomMargin) {\n topPx += bottomMargin;\n bottomPx += bottomMargin;\n }\n\n // transform new bounds into coordinates\n const [newLeftTop, newRightBottom] = utils.fromGlobalPixelBounds(\n [\n [leftPx, topPx],\n [rightPx, bottomPx],\n ],\n newZoom,\n );\n\n return {\n center: utils.getCenter([newLeftTop, newRightBottom]),\n zoom: newZoom,\n };\n};\n"]}
@@ -26,6 +26,7 @@ export { default as ImageBase } from "./ImageBase/ImageBase.js";
26
26
  export { default as InnerForm } from "./InnerForm/InnerForm.js";
27
27
  export { default as Link } from "./Link/Link.js";
28
28
  export { default as Links } from "./Links/Links.js";
29
+ export { default as Map } from "./Map/Map.js";
29
30
  export { default as Media } from "./Media/Media.js";
30
31
  export { default as MetaInfo } from "./MetaInfo/MetaInfo.js";
31
32
  export { default as OutsideClick } from "./OutsideClick/OutsideClick.js";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.YandexForm = exports.YFMWrapper = exports.VideoBlock = exports.UnpublishedLabel = exports.ToggleArrow = exports.Title = exports.ButtonTabs = exports.Table = exports.RouterLink = exports.ReactPlayer = exports.OverflowScroller = exports.OutsideClick = exports.MetaInfo = exports.Media = exports.Links = exports.Link = exports.InnerForm = exports.ImageBase = exports.Image = exports.IconWrapper = exports.HTML = exports.HeaderBreadcrumbs = exports.FullWidthBackground = exports.FullscreenMedia = exports.FullscreenImage = exports.Foldable = exports.FileLink = exports.ErrorWrapper = exports.Control = exports.ContentList = exports.CardBase = exports.BrandFooter = exports.Buttons = exports.Button = exports.BlockBase = exports.BalancedMasonry = exports.BackLink = exports.BackgroundMedia = exports.BackgroundImage = exports.Author = exports.AnimateBlock = exports.Anchor = void 0;
3
+ exports.YandexForm = exports.YFMWrapper = exports.VideoBlock = exports.UnpublishedLabel = exports.ToggleArrow = exports.Title = exports.ButtonTabs = exports.Table = exports.RouterLink = exports.ReactPlayer = exports.OverflowScroller = exports.OutsideClick = exports.MetaInfo = exports.Media = exports.Map = exports.Links = exports.Link = exports.InnerForm = exports.ImageBase = exports.Image = exports.IconWrapper = exports.HTML = exports.HeaderBreadcrumbs = exports.FullWidthBackground = exports.FullscreenMedia = exports.FullscreenImage = exports.Foldable = exports.FileLink = exports.ErrorWrapper = exports.Control = exports.ContentList = exports.CardBase = exports.BrandFooter = exports.Buttons = exports.Button = exports.BlockBase = exports.BalancedMasonry = exports.BackLink = exports.BackgroundMedia = exports.BackgroundImage = exports.Author = exports.AnimateBlock = exports.Anchor = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  var Anchor_1 = require("./Anchor/Anchor.js");
6
6
  Object.defineProperty(exports, "Anchor", { enumerable: true, get: function () { return tslib_1.__importDefault(Anchor_1).default; } });
@@ -58,6 +58,8 @@ var Link_1 = require("./Link/Link.js");
58
58
  Object.defineProperty(exports, "Link", { enumerable: true, get: function () { return tslib_1.__importDefault(Link_1).default; } });
59
59
  var Links_1 = require("./Links/Links.js");
60
60
  Object.defineProperty(exports, "Links", { enumerable: true, get: function () { return tslib_1.__importDefault(Links_1).default; } });
61
+ var Map_1 = require("./Map/Map.js");
62
+ Object.defineProperty(exports, "Map", { enumerable: true, get: function () { return tslib_1.__importDefault(Map_1).default; } });
61
63
  var Media_1 = require("./Media/Media.js");
62
64
  Object.defineProperty(exports, "Media", { enumerable: true, get: function () { return tslib_1.__importDefault(Media_1).default; } });
63
65
  var MetaInfo_1 = require("./MetaInfo/MetaInfo.js");