@blaze-cms/plugin-google-maps-fe 0.124.0-alpha.2 → 0.124.0-alpha.20

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 (76) hide show
  1. package/CHANGELOG.md +158 -0
  2. package/lib/GoogleMaps/GoogleMaps.js +4 -3
  3. package/lib/GoogleMaps/GoogleMaps.js.map +1 -1
  4. package/lib/GoogleMaps/GoogleMapsFactory.js +3 -1
  5. package/lib/GoogleMaps/GoogleMapsFactory.js.map +1 -1
  6. package/lib/GoogleMaps/GoogleMapsHtml.js +32 -0
  7. package/lib/GoogleMaps/GoogleMapsHtml.js.map +1 -0
  8. package/lib/GoogleMaps/GoogleMapsRender.js +3 -1
  9. package/lib/GoogleMaps/GoogleMapsRender.js.map +1 -1
  10. package/lib/GoogleMaps/helpers/add-zoom-listener.js.map +1 -1
  11. package/lib/GoogleMaps/helpers/build-map-shapes.js +23 -18
  12. package/lib/GoogleMaps/helpers/build-map-shapes.js.map +1 -1
  13. package/lib/GoogleMaps/helpers/build-map-type-ids.js.map +1 -1
  14. package/lib/GoogleMaps/helpers/build-query.js.map +1 -1
  15. package/lib/GoogleMaps/helpers/build-shapes-configs.js +11 -3
  16. package/lib/GoogleMaps/helpers/build-shapes-configs.js.map +1 -1
  17. package/lib/GoogleMaps/helpers/get-center-coordinates.js.map +1 -1
  18. package/lib/GoogleMaps/helpers/get-image-ids.js.map +1 -1
  19. package/lib/GoogleMaps/helpers/get-path.js.map +1 -1
  20. package/lib/GoogleMaps/helpers/index.js.map +1 -1
  21. package/lib/GoogleMaps/helpers/set-map-options.js +3 -1
  22. package/lib/GoogleMaps/helpers/set-map-options.js.map +1 -1
  23. package/lib/GoogleMaps/helpers/set-shapes.js +35 -11
  24. package/lib/GoogleMaps/helpers/set-shapes.js.map +1 -1
  25. package/lib/GoogleMaps/hooks/index.js.map +1 -1
  26. package/lib/GoogleMaps/hooks/use-get-entity-schemas.js.map +1 -1
  27. package/lib/GoogleMaps/hooks/use-get-images.js.map +1 -1
  28. package/lib/GoogleMaps/index.js.map +1 -1
  29. package/lib/GoogleMaps/queries.js +4 -4
  30. package/lib/GoogleMaps/queries.js.map +1 -1
  31. package/lib/constants.js +5 -1
  32. package/lib/constants.js.map +1 -1
  33. package/lib/index.js.map +1 -1
  34. package/lib-es/GoogleMaps/GoogleMaps.js +3 -3
  35. package/lib-es/GoogleMaps/GoogleMaps.js.map +1 -1
  36. package/lib-es/GoogleMaps/GoogleMapsFactory.js +2 -1
  37. package/lib-es/GoogleMaps/GoogleMapsFactory.js.map +1 -1
  38. package/lib-es/GoogleMaps/GoogleMapsHtml.js +18 -0
  39. package/lib-es/GoogleMaps/GoogleMapsHtml.js.map +1 -0
  40. package/lib-es/GoogleMaps/GoogleMapsRender.js +2 -1
  41. package/lib-es/GoogleMaps/GoogleMapsRender.js.map +1 -1
  42. package/lib-es/GoogleMaps/helpers/add-zoom-listener.js.map +1 -1
  43. package/lib-es/GoogleMaps/helpers/build-map-shapes.js +10 -20
  44. package/lib-es/GoogleMaps/helpers/build-map-shapes.js.map +1 -1
  45. package/lib-es/GoogleMaps/helpers/build-map-type-ids.js.map +1 -1
  46. package/lib-es/GoogleMaps/helpers/build-query.js.map +1 -1
  47. package/lib-es/GoogleMaps/helpers/build-shapes-configs.js +8 -4
  48. package/lib-es/GoogleMaps/helpers/build-shapes-configs.js.map +1 -1
  49. package/lib-es/GoogleMaps/helpers/get-center-coordinates.js.map +1 -1
  50. package/lib-es/GoogleMaps/helpers/get-image-ids.js.map +1 -1
  51. package/lib-es/GoogleMaps/helpers/get-path.js.map +1 -1
  52. package/lib-es/GoogleMaps/helpers/index.js.map +1 -1
  53. package/lib-es/GoogleMaps/helpers/set-map-options.js +4 -2
  54. package/lib-es/GoogleMaps/helpers/set-map-options.js.map +1 -1
  55. package/lib-es/GoogleMaps/helpers/set-shapes.js +37 -11
  56. package/lib-es/GoogleMaps/helpers/set-shapes.js.map +1 -1
  57. package/lib-es/GoogleMaps/hooks/index.js.map +1 -1
  58. package/lib-es/GoogleMaps/hooks/use-get-entity-schemas.js.map +1 -1
  59. package/lib-es/GoogleMaps/hooks/use-get-images.js.map +1 -1
  60. package/lib-es/GoogleMaps/index.js.map +1 -1
  61. package/lib-es/GoogleMaps/queries.js +5 -0
  62. package/lib-es/GoogleMaps/queries.js.map +1 -1
  63. package/lib-es/constants.js +3 -1
  64. package/lib-es/constants.js.map +1 -1
  65. package/lib-es/index.js.map +1 -1
  66. package/package.json +3 -3
  67. package/src/GoogleMaps/GoogleMaps.js +2 -1
  68. package/src/GoogleMaps/GoogleMapsFactory.js +2 -1
  69. package/src/GoogleMaps/GoogleMapsHtml.js +16 -0
  70. package/src/GoogleMaps/GoogleMapsRender.js +2 -1
  71. package/src/GoogleMaps/helpers/build-map-shapes.js +1 -18
  72. package/src/GoogleMaps/helpers/build-shapes-configs.js +8 -4
  73. package/src/GoogleMaps/helpers/set-map-options.js +5 -2
  74. package/src/GoogleMaps/helpers/set-shapes.js +43 -11
  75. package/src/GoogleMaps/queries.js +5 -0
  76. package/src/constants.js +8 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaze-cms/plugin-google-maps-fe",
3
- "version": "0.124.0-alpha.2",
3
+ "version": "0.124.0-alpha.20",
4
4
  "description": "Blaze Google maps plugin fe",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib-es/index.js",
@@ -28,7 +28,7 @@
28
28
  "license": "GPL-3.0",
29
29
  "dependencies": {
30
30
  "@blaze-cms/nextjs-components": "^0.124.0-alpha.2",
31
- "@blaze-cms/react-page-builder": "^0.124.0-alpha.2",
31
+ "@blaze-cms/react-page-builder": "^0.124.0-alpha.20",
32
32
  "@blaze-cms/setup-ui": "^0.92.0",
33
33
  "core-js": "^3.2.1",
34
34
  "lodash.isnumber": "^3.0.3",
@@ -44,5 +44,5 @@
44
44
  "lib/*",
45
45
  "lib-es/*"
46
46
  ],
47
- "gitHead": "52045d2ed84e79531b9634ad5ce95b89f674382a"
47
+ "gitHead": "2e9866310c28c3be1283e8f4516b0a5f889c1e42"
48
48
  }
@@ -6,6 +6,7 @@ import { useInView } from '@blaze-react/utils/lib/customHooks';
6
6
  import { functions, isEqual, omit } from 'lodash';
7
7
  import { setMapOptions, addZoomListener } from './helpers';
8
8
  import { GOOGLE_MAPS_SCRIPT, LOAD, SCRIPT, IN_VIEW_CONFIG } from '../constants';
9
+ import GoogleMapsHtml from './GoogleMapsHtml';
9
10
 
10
11
  const shouldNotUpdate = (props, nextProps) => {
11
12
  const [funcs, nextFuncs] = [functions(props), functions(nextProps)];
@@ -86,7 +87,7 @@ const GoogleMaps = ({
86
87
  if (map && typeof onMount === `function`) onMount(map, onMountProps);
87
88
  if (isIntersecting) addZoomListener(map, router, mapShapes, imageData);
88
89
 
89
- return <div className="google-maps" ref={mapRef} />;
90
+ return <GoogleMapsHtml mapRef={mapRef} />;
90
91
  };
91
92
 
92
93
  GoogleMaps.propTypes = {
@@ -3,13 +3,14 @@ import PropTypes from 'prop-types';
3
3
  import { useGetEntitySchemasAsObj } from '@blaze-cms/react-page-builder';
4
4
  import { buildShapesConfig } from './helpers';
5
5
  import GoogleMapsRender from './GoogleMapsRender';
6
+ import GoogleMapsHtml from './GoogleMapsHtml';
6
7
 
7
8
  const GoogleMapsFactory = ({ entityGroups, parent, ...otherProps }) => {
8
9
  const { data, loading, error } = useGetEntitySchemasAsObj(
9
10
  entityGroups.map(({ entity }) => entity)
10
11
  );
11
12
 
12
- if (loading) return '';
13
+ if (loading) return <GoogleMapsHtml />;
13
14
  if (error) return error.message;
14
15
 
15
16
  const shapeConfigs = buildShapesConfig(data, entityGroups, parent);
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+
4
+ const GoogleMapsFactory = ({ mapRef }) => (
5
+ <div className={`google-maps ${!mapRef ? 'loading' : ''}`} ref={mapRef} />
6
+ );
7
+
8
+ GoogleMapsFactory.propTypes = {
9
+ mapRef: PropTypes.object
10
+ };
11
+
12
+ GoogleMapsFactory.defaultProps = {
13
+ mapRef: null
14
+ };
15
+
16
+ export default GoogleMapsFactory;
@@ -6,6 +6,7 @@ import { getAction } from '@blaze-cms/react-page-builder';
6
6
  import { useGetImages } from './hooks';
7
7
  import { buildQuery, getImageIds, getCenterCoordinates, buildMapShapes } from './helpers';
8
8
  import GoogleMaps from './GoogleMaps';
9
+ import GoogleMapsHtml from './GoogleMapsHtml';
9
10
 
10
11
  const defaultQuery = getAction('getPublishedPages', 'id');
11
12
 
@@ -22,7 +23,7 @@ const GoogleMapsRender = ({ shapeConfigs, entityGroups, id, ...otherProps }) =>
22
23
  loading: imagesLoading,
23
24
  error: imagesError
24
25
  } = useGetImages(imageIds);
25
- if (loading || imagesLoading) return '';
26
+ if (loading || imagesLoading) return <GoogleMapsHtml />;
26
27
  if (error || imagesError) return null;
27
28
 
28
29
  const centerCoordinates = getCenterCoordinates(mapShapes, otherProps);
@@ -22,16 +22,6 @@ const buildMapShapes = (shapesOptions, shapesData) => {
22
22
  shapesOptions.forEach(shape => {
23
23
  const { shapeKey, entityOptions, shapeOptions } = shape;
24
24
  const { dataSummaries, enableInfoPane } = entityOptions;
25
- const {
26
- imageId,
27
- label,
28
- markerHeight,
29
- markerWidth,
30
- maxZoom,
31
- minZoom,
32
- type,
33
- useAsCenter
34
- } = shapeOptions;
35
25
 
36
26
  const shapeData = Array.isArray(shapesData[shapeKey])
37
27
  ? shapesData[shapeKey]
@@ -44,19 +34,12 @@ const buildMapShapes = (shapesOptions, shapesData) => {
44
34
  const { latitude, longitude } = getLatLong(latProp, lonProp, shapeOptions, data);
45
35
 
46
36
  const formatedShape = {
37
+ ...shapeOptions,
47
38
  latitude,
48
39
  longitude,
49
40
  dataSummaries,
50
41
  enableInfoPane,
51
- imageId,
52
- label,
53
- markerHeight,
54
- markerWidth,
55
- maxZoom,
56
- minZoom,
57
- type,
58
42
  url,
59
- useAsCenter,
60
43
  shapeData: data
61
44
  };
62
45
 
@@ -39,7 +39,7 @@ const buildFilters = filters => {
39
39
  const buiildShapeProps = (shape, shapeKey, dataSummaries, parentId, entityData, entityGroup) => {
40
40
  const { displayItems = [], filterBy } = shape;
41
41
  const { latProp, lonProp, entity } = entityGroup;
42
- const { actions } = entityData;
42
+ const { actions, relations } = entityData;
43
43
  const action = actions ? actions.getAllPublished || actions.getAll : '';
44
44
 
45
45
  const dataSummaryProps = dataSummaries
@@ -59,7 +59,10 @@ const buiildShapeProps = (shape, shapeKey, dataSummaries, parentId, entityData,
59
59
  let propsQuery = dataSummaryProps ? `${dataSummaryProps}` : '';
60
60
  propsQuery = getUpdatedPropsQuery(propsQuery, entityData);
61
61
  if (latProp && lonProp) {
62
- propsQuery = `${propsQuery} ${formatProp(latProp)} ${formatProp(lonProp)}`;
62
+ propsQuery = `${propsQuery} ${formatProp(latProp, relations)} ${formatProp(
63
+ lonProp,
64
+ relations
65
+ )}`;
63
66
  }
64
67
  if (ids.length && !propsQuery.includes(ID)) propsQuery = `${propsQuery.trim()} ${ID}`;
65
68
 
@@ -73,11 +76,12 @@ const buiildShapeProps = (shape, shapeKey, dataSummaries, parentId, entityData,
73
76
  };
74
77
  };
75
78
 
76
- const formatProp = prop => {
79
+ const formatProp = (prop, relations = []) => {
77
80
  if (!prop.includes('.')) return prop;
78
81
 
79
82
  const [mainProp, nestedProp] = prop.split('.');
80
- return `${mainProp}{${nestedProp}}`;
83
+ const idProp = relations.find(({ localField }) => localField === mainProp) ? 'id ' : '';
84
+ return `${mainProp}{${idProp}${nestedProp}}`;
81
85
  };
82
86
 
83
87
  const buildShapesConfig = (schemas, entityGroups, parent) => {
@@ -8,7 +8,8 @@ import {
8
8
  DISABLE_TRANSPORTATION_STYLES,
9
9
  DISABLE_POI_STYLES,
10
10
  DISABLE_BOUNDARIES_STYLES,
11
- DISABLE_LABELS_STYLES
11
+ DISABLE_LABELS_STYLES,
12
+ DEFAULT_SELECT_VALUE
12
13
  } from '../../constants';
13
14
 
14
15
  const setCustomColor = (featureType, color, elementType) =>
@@ -60,7 +61,8 @@ const setMapOptions = otherProps => {
60
61
  enableTerrainScreen,
61
62
  waterColor,
62
63
  landscapeColor,
63
- landscapeColorAll
64
+ landscapeColorAll,
65
+ mapType
64
66
  } = otherProps;
65
67
 
66
68
  const customColors = [
@@ -85,6 +87,7 @@ const setMapOptions = otherProps => {
85
87
  mapTypeControlOptions: {
86
88
  mapTypeIds: buildMapTypeIds(enableSatelliteView, enableTerrainScreen)
87
89
  },
90
+ mapTypeId: !mapType || mapType === DEFAULT_SELECT_VALUE ? undefined : mapType,
88
91
  styles: customColors
89
92
  };
90
93
  };
@@ -17,7 +17,8 @@ import {
17
17
  COLOR,
18
18
  CLICK,
19
19
  HEADING_LARGE,
20
- LIST
20
+ LIST,
21
+ DEFAULT_CUSTOM_MARKER_PATH
21
22
  } from '../../constants';
22
23
 
23
24
  const shapesArray = [];
@@ -142,23 +143,54 @@ const infoWindowContent = async (imageData, dataSummaries, url, shapeData) => {
142
143
  );
143
144
  };
144
145
 
146
+ function getIcon(imageData, shape) {
147
+ const {
148
+ imageId,
149
+ markerWidth = 50,
150
+ markerHeight = 50,
151
+ strokeColor,
152
+ strokeOpacity,
153
+ strokeWeight,
154
+ fillColor,
155
+ fillOpacity,
156
+ svgPath
157
+ } = shape;
158
+ const iconUrl = getIconUrl(imageId, imageData);
159
+
160
+ const icon = iconUrl
161
+ ? {
162
+ url: iconUrl,
163
+ scaledSize: new window.google.maps.Size(markerWidth || 50, markerHeight || 50)
164
+ }
165
+ : null;
166
+
167
+ if (icon) return icon;
168
+
169
+ if (!svgPath && !fillColor && !strokeColor) return {}; // any can be true for custom marker
170
+
171
+ const svgMarker = {
172
+ path: svgPath || DEFAULT_CUSTOM_MARKER_PATH,
173
+ strokeColor,
174
+ strokeOpacity,
175
+ strokeWeight,
176
+ fillColor,
177
+ fillOpacity,
178
+ rotation: 0,
179
+ scale: 2
180
+ };
181
+ return svgMarker;
182
+ }
183
+
145
184
  const setMarker = (map, router, shape, imageData) => {
146
- const { label = '', markerWidth = 50, markerHeight = 50, latitude, longitude, imageId } = shape;
185
+ const { label = '', latitude, longitude } = shape;
147
186
 
148
187
  if (isPositionCorrect(latitude, longitude)) {
149
- const iconUrl = getIconUrl(imageId, imageData);
150
-
151
- const icon = iconUrl
152
- ? {
153
- url: iconUrl,
154
- scaledSize: new window.google.maps.Size(markerWidth || 50, markerHeight || 50)
155
- }
156
- : {};
188
+ const svgMarker = getIcon(imageData, shape);
157
189
 
158
190
  const marker = new window.google.maps.Marker({
159
191
  position: { lat: latitude, lng: longitude },
160
192
  map,
161
- icon,
193
+ icon: svgMarker,
162
194
  title: label || ''
163
195
  });
164
196
 
@@ -3,10 +3,12 @@ import { gql } from '@apollo/client';
3
3
  const GET_ENTITY_SCHEMAS = gql`
4
4
  query getEntitySchemas($identifier: String) {
5
5
  getEntitySchemas(identifier: $identifier) {
6
+ id
6
7
  identifier
7
8
  actions
8
9
  dynamicProperties
9
10
  properties
11
+ relations
10
12
  }
11
13
  }
12
14
  `;
@@ -24,12 +26,14 @@ const generateWhereQuery = queryString => gql`
24
26
  `;
25
27
  const generateQueryString = (action, query, props) => `
26
28
  ${query}: ${action}(where: $where){
29
+ id
27
30
  ${props}
28
31
  }
29
32
  `;
30
33
 
31
34
  const generateIdsQuery = (query, props, action, ids) => `
32
35
  ${query}: ${action}(where: { id: { _in: ${JSON.stringify(ids)} } }){
36
+ id
33
37
  ${props}
34
38
  }
35
39
  `;
@@ -38,6 +42,7 @@ const generateFiltersQuery = (query, props, rawQUery, filterQueryKey) => `
38
42
  ${query}: searchPublishedContent(rawQueryStringified: ${JSON.stringify(rawQUery)}){
39
43
  results {
40
44
  ...on ${filterQueryKey} {
45
+ id
41
46
  ${props}
42
47
  }
43
48
  }
package/src/constants.js CHANGED
@@ -122,6 +122,11 @@ const IN_VIEW_CONFIG = {
122
122
  offset: '200px'
123
123
  };
124
124
 
125
+ const DEFAULT_SELECT_VALUE = 'Default';
126
+
127
+ const DEFAULT_CUSTOM_MARKER_PATH =
128
+ 'M12,11.5A2.5,2.5 0 0,1 9.5,9A2.5,2.5 0 0,1 12,6.5A2.5,2.5 0 0,1 14.5,9A2.5,2.5 0 0,1 12,11.5M12,2A7,7 0 0,0 5,9C5,14.25 12,22 12,22C12,22 19,14.25 19,9A7,7 0 0,0 12,2Z';
129
+
125
130
  export {
126
131
  PLUGIN_NAME,
127
132
  GOOGLE_MAPS_SCRIPT,
@@ -155,5 +160,7 @@ export {
155
160
  DISABLE_TRANSPORTATION_STYLES,
156
161
  DISABLE_POI_STYLES,
157
162
  DISABLE_BOUNDARIES_STYLES,
158
- DISABLE_LABELS_STYLES
163
+ DISABLE_LABELS_STYLES,
164
+ DEFAULT_SELECT_VALUE,
165
+ DEFAULT_CUSTOM_MARKER_PATH
159
166
  };