@gravity-ui/page-constructor 1.18.1 → 1.19.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 (124) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +8 -0
  3. package/build/cjs/blocks/Map/Map.d.ts +3 -0
  4. package/build/cjs/blocks/Map/Map.js +15 -0
  5. package/build/cjs/blocks/Map/schema.d.ts +370 -0
  6. package/build/cjs/blocks/Map/schema.js +18 -0
  7. package/build/cjs/blocks/Media/Media.js +5 -27
  8. package/build/cjs/blocks/Media/schema.d.ts +265 -9
  9. package/build/cjs/blocks/Media/schema.js +18 -17
  10. package/build/cjs/blocks/index.d.ts +1 -0
  11. package/build/cjs/blocks/index.js +3 -1
  12. package/build/cjs/components/Map/GoogleMap.d.ts +4 -0
  13. package/build/cjs/components/Map/GoogleMap.js +42 -0
  14. package/build/cjs/components/Map/Map.css +20 -0
  15. package/build/cjs/components/Map/Map.d.ts +3 -0
  16. package/build/cjs/components/Map/Map.js +21 -0
  17. package/build/cjs/components/Map/YMap/YMap.d.ts +13 -0
  18. package/build/cjs/components/Map/YMap/YMap.js +97 -0
  19. package/build/cjs/components/Map/YMap/YandexMap.d.ts +4 -0
  20. package/build/cjs/components/Map/YMap/YandexMap.js +72 -0
  21. package/build/cjs/components/Map/YMap/YandexMapApiLoader.d.ts +11 -0
  22. package/build/cjs/components/Map/YMap/YandexMapApiLoader.js +37 -0
  23. package/build/cjs/components/Map/YMap/i18n/en.json +4 -0
  24. package/build/cjs/components/Map/YMap/i18n/index.d.ts +2 -0
  25. package/build/cjs/components/Map/YMap/i18n/index.js +8 -0
  26. package/build/cjs/components/Map/YMap/i18n/ru.json +4 -0
  27. package/build/cjs/components/Map/helpers.d.ts +1 -0
  28. package/build/cjs/components/Map/helpers.js +7 -0
  29. package/build/cjs/{blocks/Media/Media.css → components/MediaBase/MediaBase.css} +15 -14
  30. package/build/cjs/components/MediaBase/MediaBase.d.ts +13 -0
  31. package/build/cjs/components/MediaBase/MediaBase.js +39 -0
  32. package/build/{esm/blocks/Media/MediaContent.css → cjs/components/MediaBase/MediaBaseContent.css} +2 -2
  33. package/build/cjs/{blocks/Media/MediaContent.js → components/MediaBase/MediaBaseContent.js} +1 -1
  34. package/build/cjs/constructor-items.d.ts +1 -0
  35. package/build/cjs/constructor-items.js +1 -0
  36. package/build/cjs/containers/PageConstructor/Provider.d.ts +2 -0
  37. package/build/cjs/containers/PageConstructor/Provider.js +3 -1
  38. package/build/cjs/context/mapsContext/mapsContext.d.ts +22 -0
  39. package/build/cjs/context/mapsContext/mapsContext.js +20 -0
  40. package/build/cjs/context/mapsContext/mapsProvider.d.ts +10 -0
  41. package/build/cjs/context/mapsContext/mapsProvider.js +15 -0
  42. package/build/cjs/context/mapsContext/useMap.d.ts +2 -0
  43. package/build/cjs/context/mapsContext/useMap.js +11 -0
  44. package/build/cjs/internal-typings/global.d.ts +36 -0
  45. package/build/cjs/models/constructor-items/blocks.d.ts +18 -9
  46. package/build/cjs/models/constructor-items/blocks.js +1 -0
  47. package/build/cjs/models/constructor-items/common.d.ts +25 -0
  48. package/build/cjs/schema/index.js +1 -1
  49. package/build/cjs/schema/validators/blocks.d.ts +1 -0
  50. package/build/cjs/schema/validators/blocks.js +1 -0
  51. package/build/cjs/schema/validators/common.d.ts +91 -0
  52. package/build/cjs/schema/validators/common.js +46 -1
  53. package/build/cjs/utils/blocks.d.ts +1 -1
  54. package/build/cjs/utils/common.d.ts +6 -0
  55. package/build/cjs/utils/common.js +24 -0
  56. package/build/cjs/utils/index.d.ts +1 -0
  57. package/build/cjs/utils/index.js +1 -0
  58. package/build/esm/blocks/Map/Map.d.ts +3 -0
  59. package/build/esm/blocks/Map/Map.js +11 -0
  60. package/build/esm/blocks/Map/schema.d.ts +370 -0
  61. package/build/esm/blocks/Map/schema.js +15 -0
  62. package/build/esm/blocks/Media/Media.d.ts +0 -1
  63. package/build/esm/blocks/Media/Media.js +7 -31
  64. package/build/esm/blocks/Media/schema.d.ts +265 -9
  65. package/build/esm/blocks/Media/schema.js +17 -16
  66. package/build/esm/blocks/index.d.ts +1 -0
  67. package/build/esm/blocks/index.js +1 -0
  68. package/build/esm/components/Map/GoogleMap.d.ts +4 -0
  69. package/build/esm/components/Map/GoogleMap.js +39 -0
  70. package/build/esm/components/Map/Map.css +20 -0
  71. package/build/esm/components/Map/Map.d.ts +4 -0
  72. package/build/esm/components/Map/Map.js +17 -0
  73. package/build/esm/components/Map/YMap/YMap.d.ts +13 -0
  74. package/build/esm/components/Map/YMap/YMap.js +93 -0
  75. package/build/esm/components/Map/YMap/YandexMap.d.ts +4 -0
  76. package/build/esm/components/Map/YMap/YandexMap.js +69 -0
  77. package/build/esm/components/Map/YMap/YandexMapApiLoader.d.ts +11 -0
  78. package/build/esm/components/Map/YMap/YandexMapApiLoader.js +33 -0
  79. package/build/esm/components/Map/YMap/i18n/en.json +4 -0
  80. package/build/esm/components/Map/YMap/i18n/index.d.ts +2 -0
  81. package/build/esm/components/Map/YMap/i18n/index.js +5 -0
  82. package/build/esm/components/Map/YMap/i18n/ru.json +4 -0
  83. package/build/esm/components/Map/helpers.d.ts +1 -0
  84. package/build/esm/components/Map/helpers.js +3 -0
  85. package/build/esm/{blocks/Media/Media.css → components/MediaBase/MediaBase.css} +15 -14
  86. package/build/esm/components/MediaBase/MediaBase.d.ts +14 -0
  87. package/build/esm/components/MediaBase/MediaBase.js +36 -0
  88. package/build/{cjs/blocks/Media/MediaContent.css → esm/components/MediaBase/MediaBaseContent.css} +2 -2
  89. package/build/esm/{blocks/Media/MediaContent.d.ts → components/MediaBase/MediaBaseContent.d.ts} +1 -1
  90. package/build/esm/{blocks/Media/MediaContent.js → components/MediaBase/MediaBaseContent.js} +2 -2
  91. package/build/esm/constructor-items.d.ts +1 -0
  92. package/build/esm/constructor-items.js +2 -1
  93. package/build/esm/containers/PageConstructor/Provider.d.ts +2 -0
  94. package/build/esm/containers/PageConstructor/Provider.js +3 -1
  95. package/build/esm/context/mapsContext/mapsContext.d.ts +22 -0
  96. package/build/esm/context/mapsContext/mapsContext.js +16 -0
  97. package/build/esm/context/mapsContext/mapsProvider.d.ts +10 -0
  98. package/build/esm/context/mapsContext/mapsProvider.js +10 -0
  99. package/build/esm/context/mapsContext/useMap.d.ts +2 -0
  100. package/build/esm/context/mapsContext/useMap.js +6 -0
  101. package/build/esm/internal-typings/global.d.ts +36 -0
  102. package/build/esm/models/constructor-items/blocks.d.ts +18 -9
  103. package/build/esm/models/constructor-items/blocks.js +1 -0
  104. package/build/esm/models/constructor-items/common.d.ts +25 -0
  105. package/build/esm/schema/index.js +2 -2
  106. package/build/esm/schema/validators/blocks.d.ts +1 -0
  107. package/build/esm/schema/validators/blocks.js +1 -0
  108. package/build/esm/schema/validators/common.d.ts +91 -0
  109. package/build/esm/schema/validators/common.js +45 -0
  110. package/build/esm/utils/blocks.d.ts +1 -1
  111. package/build/esm/utils/common.d.ts +6 -0
  112. package/build/esm/utils/common.js +20 -0
  113. package/build/esm/utils/index.d.ts +1 -0
  114. package/build/esm/utils/index.js +1 -0
  115. package/package.json +1 -1
  116. package/server/models/constructor-items/blocks.d.ts +18 -9
  117. package/server/models/constructor-items/blocks.js +1 -0
  118. package/server/models/constructor-items/common.d.ts +25 -0
  119. package/server/utils/blocks.d.ts +1 -1
  120. package/server/utils/common.d.ts +6 -0
  121. package/server/utils/common.js +24 -0
  122. package/server/utils/index.d.ts +1 -0
  123. package/server/utils/index.js +1 -0
  124. /package/build/cjs/{blocks/Media/MediaContent.d.ts → components/MediaBase/MediaBaseContent.d.ts} +0 -0
@@ -133,32 +133,267 @@ export declare const Media: {
133
133
  };
134
134
  };
135
135
  };
136
- export declare const MediaBlock: {
137
- 'media-block': {
136
+ export declare const MediaBlockBaseProps: {
137
+ description: {
138
+ type: string;
139
+ contentType: string;
140
+ };
141
+ direction: {
142
+ type: string;
143
+ enum: string[];
144
+ };
145
+ mobileDirection: {
146
+ type: string;
147
+ enum: string[];
148
+ };
149
+ largeMedia: {
150
+ type: string;
151
+ };
152
+ mediaOnly: {
153
+ type: string;
154
+ };
155
+ disableShadow: {
156
+ type: string;
157
+ };
158
+ button: {
159
+ type: string;
138
160
  additionalProperties: boolean;
139
- required: string[];
140
161
  properties: {
141
- description: {
162
+ text: {
142
163
  type: string;
143
164
  contentType: string;
144
165
  };
145
- direction: {
166
+ url: {
167
+ type: string;
168
+ };
169
+ primary: {
170
+ type: string;
171
+ };
172
+ size: {
146
173
  type: string;
147
174
  enum: string[];
148
175
  };
149
- mobileDirection: {
176
+ theme: {
150
177
  type: string;
151
178
  enum: string[];
152
179
  };
153
- largeMedia: {
180
+ img: {
181
+ anyOf: ({
182
+ type: string;
183
+ additionalProperties?: undefined;
184
+ required?: undefined;
185
+ properties?: undefined;
186
+ } | {
187
+ type: string;
188
+ additionalProperties: boolean;
189
+ required: string[];
190
+ properties: {
191
+ data: {
192
+ type: string;
193
+ };
194
+ position: {
195
+ type: string;
196
+ enum: string[];
197
+ };
198
+ alt: {
199
+ type: string;
200
+ contentType: string;
201
+ };
202
+ };
203
+ })[];
204
+ };
205
+ metrikaGoals: {
206
+ anyOf: ({
207
+ type: string;
208
+ items?: undefined;
209
+ } | {
210
+ type: string;
211
+ items: {
212
+ type: string;
213
+ additionalProperties?: undefined;
214
+ required?: undefined;
215
+ properties?: undefined;
216
+ };
217
+ } | {
218
+ type: string;
219
+ items: {
220
+ type: string;
221
+ additionalProperties: boolean;
222
+ required: string[];
223
+ properties: {
224
+ name: {
225
+ type: string;
226
+ };
227
+ isCrossSite: {
228
+ type: string;
229
+ };
230
+ };
231
+ };
232
+ })[];
233
+ };
234
+ pixelEvents: {
235
+ type: string;
236
+ items: {
237
+ type: string;
238
+ required: string[];
239
+ additionalProperties: boolean;
240
+ properties: {
241
+ name: {
242
+ type: string;
243
+ enum: import("../..").PixelEventType[];
244
+ };
245
+ data: {};
246
+ };
247
+ select: {
248
+ $data: string;
249
+ };
250
+ selectCases: {
251
+ SubmitApplication: {
252
+ additionalProperties: boolean;
253
+ properties: {
254
+ name: {};
255
+ };
256
+ };
257
+ Contact: {
258
+ additionalProperties: boolean;
259
+ properties: {
260
+ name: {};
261
+ };
262
+ };
263
+ Lead: {
264
+ additionalProperties: boolean;
265
+ properties: {
266
+ name: {};
267
+ data: {
268
+ type: string;
269
+ additionalProperties: boolean;
270
+ properties: {
271
+ content_category: {
272
+ type: string;
273
+ };
274
+ content_name: {
275
+ type: string;
276
+ };
277
+ currency: {
278
+ type: string;
279
+ };
280
+ value: {
281
+ type: string;
282
+ };
283
+ };
284
+ };
285
+ };
286
+ };
287
+ };
288
+ };
289
+ };
290
+ target: {
154
291
  type: string;
292
+ enum: string[];
155
293
  };
156
- mediaOnly: {
294
+ };
295
+ if: {
296
+ properties: {
297
+ theme: {
298
+ enum: string[];
299
+ };
300
+ };
301
+ };
302
+ then: {
303
+ required: string[];
304
+ };
305
+ else: {
306
+ required: string[];
307
+ };
308
+ };
309
+ title: {
310
+ oneOf: ({
311
+ type: string;
312
+ additionalProperties: boolean;
313
+ required: string[];
314
+ properties: {
315
+ text: {
316
+ type: string;
317
+ contentType: string;
318
+ };
319
+ textSize: {
320
+ type: string;
321
+ enum: string[];
322
+ };
323
+ url: {
324
+ type: string;
325
+ };
326
+ resetMargin: {
327
+ type: string;
328
+ };
329
+ };
330
+ } | {
331
+ type: string;
332
+ contentType: string;
333
+ })[];
334
+ };
335
+ size: {
336
+ type: string;
337
+ enum: string[];
338
+ };
339
+ additionalInfo: {
340
+ type: string;
341
+ contentType: string;
342
+ };
343
+ links: {
344
+ type: string;
345
+ items: {
346
+ type: string;
347
+ properties: {
348
+ when: {
349
+ type: string;
350
+ };
351
+ };
352
+ };
353
+ };
354
+ buttons: {
355
+ type: string;
356
+ items: {
357
+ type: string;
358
+ properties: {
359
+ when: {
360
+ type: string;
361
+ };
362
+ };
363
+ };
364
+ };
365
+ animated: {
366
+ type: string;
367
+ };
368
+ anchor: {
369
+ type: string;
370
+ additionalProperties: boolean;
371
+ required: string[];
372
+ properties: {
373
+ text: {
157
374
  type: string;
375
+ contentType: string;
158
376
  };
159
- disableShadow: {
377
+ url: {
160
378
  type: string;
161
379
  };
380
+ };
381
+ };
382
+ visible: {
383
+ type: string;
384
+ enum: string[];
385
+ };
386
+ resetPaddings: {
387
+ type: string;
388
+ };
389
+ type: {};
390
+ when: {};
391
+ };
392
+ export declare const MediaBlock: {
393
+ 'media-block': {
394
+ additionalProperties: boolean;
395
+ required: string[];
396
+ properties: {
162
397
  media: {
163
398
  type: string;
164
399
  additionalProperties: boolean;
@@ -294,6 +529,27 @@ export declare const MediaBlock: {
294
529
  };
295
530
  };
296
531
  };
532
+ description: {
533
+ type: string;
534
+ contentType: string;
535
+ };
536
+ direction: {
537
+ type: string;
538
+ enum: string[];
539
+ };
540
+ mobileDirection: {
541
+ type: string;
542
+ enum: string[];
543
+ };
544
+ largeMedia: {
545
+ type: string;
546
+ };
547
+ mediaOnly: {
548
+ type: string;
549
+ };
550
+ disableShadow: {
551
+ type: string;
552
+ };
297
553
  button: {
298
554
  type: string;
299
555
  additionalProperties: boolean;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MediaBlock = exports.Media = void 0;
3
+ exports.MediaBlock = exports.MediaBlockBaseProps = exports.Media = void 0;
4
4
  const lodash_1 = require("lodash");
5
5
  const common_1 = require("../../schema/validators/common");
6
6
  const schema_1 = require("../../sub-blocks/Content/schema");
@@ -11,25 +11,26 @@ exports.Media = {
11
11
  properties: common_1.MediaProps,
12
12
  };
13
13
  const MediaBlockContentProps = (0, lodash_1.omit)(schema_1.ContentBase, ['text', 'theme']);
14
+ exports.MediaBlockBaseProps = Object.assign(Object.assign(Object.assign(Object.assign({}, common_1.BlockBaseProps), common_1.AnimatableProps), MediaBlockContentProps), { description: {
15
+ type: 'string',
16
+ contentType: 'yfm',
17
+ }, direction: {
18
+ type: 'string',
19
+ enum: common_1.mediaDirection,
20
+ }, mobileDirection: {
21
+ type: 'string',
22
+ enum: common_1.mediaDirection,
23
+ }, largeMedia: {
24
+ type: 'boolean',
25
+ }, mediaOnly: {
26
+ type: 'boolean',
27
+ }, disableShadow: {
28
+ type: 'boolean',
29
+ }, button: common_1.ButtonBlock });
14
30
  exports.MediaBlock = {
15
31
  'media-block': {
16
32
  additionalProperties: false,
17
33
  required: ['title', 'media'],
18
- properties: Object.assign(Object.assign(Object.assign(Object.assign({}, common_1.BlockBaseProps), common_1.AnimatableProps), MediaBlockContentProps), { description: {
19
- type: 'string',
20
- contentType: 'yfm',
21
- }, direction: {
22
- type: 'string',
23
- enum: common_1.mediaDirection,
24
- }, mobileDirection: {
25
- type: 'string',
26
- enum: common_1.mediaDirection,
27
- }, largeMedia: {
28
- type: 'boolean',
29
- }, mediaOnly: {
30
- type: 'boolean',
31
- }, disableShadow: {
32
- type: 'boolean',
33
- }, media: exports.Media, button: common_1.ButtonBlock }),
34
+ properties: Object.assign(Object.assign({}, exports.MediaBlockBaseProps), { media: exports.Media }),
34
35
  },
35
36
  };
@@ -3,6 +3,7 @@ export { default as CompaniesBlock } from './Companies/Companies';
3
3
  export { default as SimpleBlock } from './Simple/Simple';
4
4
  export { default as InfoBlock } from './Info/Info';
5
5
  export { default as MediaBlock } from './Media/Media';
6
+ export { default as MapBlock } from './Map/Map';
6
7
  export { default as PreviewBlock } from './Preview/Preview';
7
8
  export { default as SecurityBlock } from './Security/Security';
8
9
  export { default as SliderBlock } from './Slider/Slider';
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ShareBlock = exports.ContentLayoutBlock = exports.CardLayoutBlock = exports.HeaderSliderBlock = exports.IconsBlock = exports.HeaderBlock = exports.LinkTableBlock = exports.TabsBlock = exports.TableBlock = exports.QuestionsBlock = exports.PromoFeaturesBlock = exports.ExtendedFeaturesBlock = exports.SliderBlock = exports.SecurityBlock = exports.PreviewBlock = exports.MediaBlock = exports.InfoBlock = exports.SimpleBlock = exports.CompaniesBlock = exports.BannerBlock = void 0;
6
+ exports.ShareBlock = exports.ContentLayoutBlock = exports.CardLayoutBlock = exports.HeaderSliderBlock = exports.IconsBlock = exports.HeaderBlock = exports.LinkTableBlock = exports.TabsBlock = exports.TableBlock = exports.QuestionsBlock = exports.PromoFeaturesBlock = exports.ExtendedFeaturesBlock = exports.SliderBlock = exports.SecurityBlock = exports.PreviewBlock = exports.MapBlock = exports.MediaBlock = exports.InfoBlock = exports.SimpleBlock = exports.CompaniesBlock = exports.BannerBlock = void 0;
7
7
  var Banner_1 = require("./Banner/Banner");
8
8
  Object.defineProperty(exports, "BannerBlock", { enumerable: true, get: function () { return __importDefault(Banner_1).default; } });
9
9
  var Companies_1 = require("./Companies/Companies");
@@ -14,6 +14,8 @@ var Info_1 = require("./Info/Info");
14
14
  Object.defineProperty(exports, "InfoBlock", { enumerable: true, get: function () { return __importDefault(Info_1).default; } });
15
15
  var Media_1 = require("./Media/Media");
16
16
  Object.defineProperty(exports, "MediaBlock", { enumerable: true, get: function () { return __importDefault(Media_1).default; } });
17
+ var Map_1 = require("./Map/Map");
18
+ Object.defineProperty(exports, "MapBlock", { enumerable: true, get: function () { return __importDefault(Map_1).default; } });
17
19
  var Preview_1 = require("./Preview/Preview");
18
20
  Object.defineProperty(exports, "PreviewBlock", { enumerable: true, get: function () { return __importDefault(Preview_1).default; } });
19
21
  var Security_1 = require("./Security/Security");
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { GMapProps } from '../../models';
3
+ declare const GoogleMap: React.FC<GMapProps>;
4
+ export default GoogleMap;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const react_1 = tslib_1.__importStar(require("react"));
5
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
6
+ const utils_1 = require("../../utils");
7
+ const mapsContext_1 = require("../../context/mapsContext/mapsContext");
8
+ const localeContext_1 = require("../../context/localeContext/localeContext");
9
+ const mobileContext_1 = require("../../context/mobileContext");
10
+ const helpers_1 = require("./helpers");
11
+ const b = (0, utils_1.block)('map');
12
+ function getScriptSrc(apiKey, scriptSrc, address, lang) {
13
+ return `${scriptSrc}?key=${apiKey}&language=${lang}&q=${encodeURI(address)}`;
14
+ }
15
+ const GoogleMap = (props) => {
16
+ const { address } = props;
17
+ const { apiKey, scriptSrc } = (0, react_1.useContext)(mapsContext_1.MapsContext);
18
+ const { lang = 'ru' } = (0, react_1.useContext)(localeContext_1.LocaleContext);
19
+ const isMobile = (0, react_1.useContext)(mobileContext_1.MobileContext);
20
+ const [height, setHeight] = (0, react_1.useState)(undefined);
21
+ const ref = (0, react_1.useRef)(null);
22
+ const src = (0, react_1.useMemo)(() => getScriptSrc(apiKey, scriptSrc, address, lang), [apiKey, scriptSrc, address, lang]);
23
+ (0, react_1.useEffect)(() => {
24
+ const updateSize = lodash_1.default.debounce(() => {
25
+ if (ref.current) {
26
+ setHeight(Math.round((0, helpers_1.getMapHeight)(ref.current.offsetWidth, isMobile)));
27
+ }
28
+ }, 100);
29
+ updateSize();
30
+ window.addEventListener('resize', updateSize);
31
+ return () => {
32
+ window.removeEventListener('resize', updateSize);
33
+ };
34
+ }, [isMobile]);
35
+ if (!apiKey || !address) {
36
+ return null;
37
+ }
38
+ return (react_1.default.createElement("iframe", { className: b(), ref: ref, style: {
39
+ height,
40
+ }, loading: "lazy", allowFullScreen: true, referrerPolicy: "no-referrer-when-downgrade", src: src }));
41
+ };
42
+ exports.default = GoogleMap;
@@ -0,0 +1,20 @@
1
+ /* use this for style redefinitions to awoid problems with
2
+ unpredictable css rules order in build */
3
+ .pc-map {
4
+ width: 100%;
5
+ height: 300px;
6
+ border: 0;
7
+ overflow: hidden;
8
+ display: flex;
9
+ }
10
+ .pc-map__spinner {
11
+ margin: 0 auto;
12
+ align-self: center;
13
+ }
14
+ .pc-map__wrapper {
15
+ min-height: 300px;
16
+ display: flex;
17
+ flex-direction: column;
18
+ align-items: center;
19
+ justify-content: center;
20
+ }
@@ -0,0 +1,3 @@
1
+ import { MapProps } from '../../models';
2
+ export declare const Map: (props: MapProps) => JSX.Element | null;
3
+ export default Map;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Map = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importStar(require("react"));
6
+ const mapsContext_1 = require("../../context/mapsContext/mapsContext");
7
+ const YandexMap_1 = tslib_1.__importDefault(require("./YMap/YandexMap"));
8
+ const GoogleMap_1 = tslib_1.__importDefault(require("./GoogleMap"));
9
+ const Map = (props) => {
10
+ const { type } = (0, react_1.useContext)(mapsContext_1.MapsContext);
11
+ switch (type) {
12
+ case mapsContext_1.MapType.Yandex:
13
+ return react_1.default.createElement(YandexMap_1.default, Object.assign({}, props));
14
+ case mapsContext_1.MapType.Google:
15
+ return react_1.default.createElement(GoogleMap_1.default, Object.assign({}, props));
16
+ default:
17
+ return null;
18
+ }
19
+ };
20
+ exports.Map = Map;
21
+ exports.default = exports.Map;
@@ -0,0 +1,13 @@
1
+ import { YMapMarker } from '../../../models';
2
+ export declare class YMap {
3
+ private ymap;
4
+ private mapRef;
5
+ private coords;
6
+ constructor(ymap: Ymaps.Map, mapRef: HTMLDivElement | null);
7
+ showPlacemarks(markers: YMapMarker[]): Promise<void>;
8
+ findAddress(marker: YMapMarker): Promise<void>;
9
+ findCoordinate(marker: YMapMarker): void;
10
+ private drawPlaceMarkStyle;
11
+ private recalcZoomAndCenter;
12
+ private clearOldPlacemarks;
13
+ }
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.YMap = void 0;
4
+ var GeoObjectTypes;
5
+ (function (GeoObjectTypes) {
6
+ GeoObjectTypes["Properties"] = "properties";
7
+ GeoObjectTypes["Options"] = "options";
8
+ })(GeoObjectTypes || (GeoObjectTypes = {}));
9
+ const DEFAULT_PLACEMARKS_COLOR = '#dc534b';
10
+ // presetStorage: https://yandex.com/dev/maps/jsapi/doc/2.1/ref/reference/option.presetStorage.html
11
+ const DEFAULT_PLACEMARKS_PRESET = 'islands#dotIcon';
12
+ const DEFAULT_MAP_CONTROL_BUTTON_HEIGHT = 30;
13
+ const geoObjectPropsAndOptions = {
14
+ iconCaption: GeoObjectTypes.Properties,
15
+ iconContent: GeoObjectTypes.Properties,
16
+ iconColor: GeoObjectTypes.Options,
17
+ preset: GeoObjectTypes.Options,
18
+ };
19
+ class YMap {
20
+ constructor(ymap, mapRef) {
21
+ this.coords = [];
22
+ this.ymap = ymap;
23
+ this.mapRef = mapRef;
24
+ }
25
+ async showPlacemarks(markers) {
26
+ this.clearOldPlacemarks();
27
+ for (const marker of markers) {
28
+ if (marker.address) {
29
+ await this.findAddress(marker);
30
+ }
31
+ else if (marker.coordinate) {
32
+ this.findCoordinate(marker);
33
+ }
34
+ }
35
+ this.recalcZoomAndCenter();
36
+ }
37
+ async findAddress(marker) {
38
+ try {
39
+ const res = await window.ymaps.geocode(marker.address, { results: 1 });
40
+ const geoObject = res.geoObjects.get(0);
41
+ const coordinate = geoObject.geometry.getCoordinates();
42
+ this.coords.push(coordinate);
43
+ this.drawPlaceMarkStyle(geoObject, marker);
44
+ this.ymap.geoObjects.add(geoObject);
45
+ }
46
+ catch (_a) { } // If error - placemark will not be displayed
47
+ }
48
+ findCoordinate(marker) {
49
+ const geoObject = new window.ymaps.Placemark(marker.coordinate, {});
50
+ this.coords.push(marker.coordinate);
51
+ this.drawPlaceMarkStyle(geoObject, marker);
52
+ this.ymap.geoObjects.add(geoObject);
53
+ }
54
+ drawPlaceMarkStyle(geoObject, marker) {
55
+ if (!marker.label) {
56
+ return;
57
+ }
58
+ const { iconColor, preset = DEFAULT_PLACEMARKS_PRESET } = marker.label;
59
+ let localIconColor = iconColor;
60
+ // You can set the preset option together with the iconColor option only if it not a 'Stretchy' preset
61
+ if (!preset.includes('Stretchy') && !iconColor) {
62
+ localIconColor = DEFAULT_PLACEMARKS_COLOR;
63
+ }
64
+ Object.entries(Object.assign(Object.assign({}, marker.label), { iconColor: localIconColor, preset })).forEach(([key, value]) => {
65
+ const geoObjectParamType = geoObjectPropsAndOptions[key];
66
+ if (value && geoObjectParamType) {
67
+ geoObject[geoObjectParamType].set(key, value);
68
+ }
69
+ });
70
+ }
71
+ recalcZoomAndCenter() {
72
+ var _a, _b;
73
+ const coordsLength = this.coords.length;
74
+ if (!coordsLength) {
75
+ return;
76
+ }
77
+ let leftBottom = [Infinity, Infinity], rightTop = [-Infinity, -Infinity];
78
+ this.coords.forEach((point) => {
79
+ leftBottom = [Math.min(leftBottom[0], point[0]), Math.min(leftBottom[1], point[1])];
80
+ rightTop = [Math.max(rightTop[0], point[0]), Math.max(rightTop[1], point[1])];
81
+ });
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 });
83
+ this.ymap.setCenter(newMapParams.center);
84
+ // Use default zoom for one placemark
85
+ if (coordsLength > 1) {
86
+ this.ymap.setZoom(newMapParams.zoom);
87
+ }
88
+ }
89
+ clearOldPlacemarks() {
90
+ if (this.coords.length === 0) {
91
+ return;
92
+ }
93
+ this.ymap.geoObjects.removeAll();
94
+ this.coords = [];
95
+ }
96
+ }
97
+ exports.YMap = YMap;
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { YMapProps } from '../../../models';
3
+ declare const YandexMap: React.FC<YMapProps>;
4
+ export default YandexMap;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const react_1 = tslib_1.__importStar(require("react"));
5
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
6
+ const uikit_1 = require("@gravity-ui/uikit");
7
+ const utils_1 = require("../../../utils");
8
+ const mapsContext_1 = require("../../../context/mapsContext/mapsContext");
9
+ const localeContext_1 = require("../../../context/localeContext/localeContext");
10
+ const ErrorWrapper_1 = tslib_1.__importDefault(require("../../ErrorWrapper/ErrorWrapper"));
11
+ const YMap_1 = require("./YMap");
12
+ const YandexMapApiLoader_1 = require("./YandexMapApiLoader");
13
+ const i18n_1 = tslib_1.__importDefault(require("./i18n"));
14
+ const mobileContext_1 = require("../../../context/mobileContext");
15
+ const helpers_1 = require("../helpers");
16
+ const b = (0, utils_1.block)('map');
17
+ const DEFAULT_CONTAINER_ID = 'ymap';
18
+ const DEFAULT_ZOOM = 9;
19
+ const YandexMap = (props) => {
20
+ const { markers, zoom, center, id } = props;
21
+ const { apiKey, scriptSrc, nonce } = (0, react_1.useContext)(mapsContext_1.MapsContext);
22
+ const isMobile = (0, react_1.useContext)(mobileContext_1.MobileContext);
23
+ const { lang = 'ru' } = (0, react_1.useContext)(localeContext_1.LocaleContext);
24
+ const containerId = `${DEFAULT_CONTAINER_ID}-${id}`;
25
+ const [ymap, setYmaps] = (0, react_1.useState)(null);
26
+ const [height, setHeight] = (0, react_1.useState)(undefined);
27
+ const ref = (0, react_1.useRef)(null);
28
+ const [loading, setLoading] = (0, react_1.useState)(false);
29
+ const [attemptsIndex, setAttemptsIndex] = (0, react_1.useState)(0);
30
+ const onTryAgain = (0, react_1.useCallback)(() => {
31
+ setAttemptsIndex(attemptsIndex + 1);
32
+ }, [attemptsIndex]);
33
+ (0, react_1.useEffect)(() => {
34
+ (async function () {
35
+ var _a;
36
+ if (!center) {
37
+ return;
38
+ }
39
+ setLoading(true);
40
+ await YandexMapApiLoader_1.YMapsApiLoader.loadApi(apiKey, scriptSrc, lang, nonce);
41
+ (_a = window.ymaps) === null || _a === void 0 ? void 0 : _a.ready(() => {
42
+ setYmaps(new YMap_1.YMap(new window.ymaps.Map(containerId, {
43
+ center,
44
+ zoom: zoom || DEFAULT_ZOOM,
45
+ }, { autoFitToViewport: 'always' }), ref.current));
46
+ });
47
+ setLoading(false);
48
+ })();
49
+ }, [apiKey, lang, scriptSrc, containerId, zoom, center, nonce, attemptsIndex, setLoading]);
50
+ (0, react_1.useEffect)(() => {
51
+ const updateSize = lodash_1.default.debounce(() => {
52
+ if (ref.current) {
53
+ setHeight(Math.round((0, helpers_1.getMapHeight)(ref.current.offsetWidth, isMobile)));
54
+ }
55
+ }, 100);
56
+ updateSize();
57
+ window.addEventListener('resize', updateSize);
58
+ return () => {
59
+ window.removeEventListener('resize', updateSize);
60
+ };
61
+ }, [markers, ymap, setYmaps, isMobile]);
62
+ (0, react_1.useEffect)(() => {
63
+ if (ymap) {
64
+ ymap.showPlacemarks(markers);
65
+ }
66
+ });
67
+ if (!center)
68
+ return null;
69
+ 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)));
71
+ };
72
+ exports.default = YandexMap;
@@ -0,0 +1,11 @@
1
+ export declare enum MapApiStatus {
2
+ NotStarted = "not_started",
3
+ Loading = "loading",
4
+ Loaded = "loaded",
5
+ Error = "error"
6
+ }
7
+ export declare class YMapsApiLoader {
8
+ static status: MapApiStatus;
9
+ static loader: Promise<unknown>;
10
+ static loadApi(apiKey: string, scriptSrc: string, lang: 'ru' | 'en', nonce?: string): Promise<unknown>;
11
+ }