neo.mjs 4.4.9 → 4.4.11

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.
@@ -1,6 +1,7 @@
1
1
  import Button from '../../../../src/button/Base.mjs';
2
2
  import GoogleMapsComponent from '../../../../src/component/wrapper/GoogleMaps.mjs';
3
3
  import MainContainerController from './MainContainerController.mjs';
4
+ import NumberField from '../../../../src/form/field/Number.mjs';
4
5
  import Toolbar from '../../../../src/toolbar/Base.mjs';
5
6
  import Viewport from '../../../../src/container/Viewport.mjs';
6
7
 
@@ -18,7 +19,15 @@ class MainContainer extends Viewport {
18
19
  items: [{
19
20
  module : GoogleMapsComponent,
20
21
  flex : 1,
21
- reference: 'google-maps-component'
22
+ reference: 'google-maps-component',
23
+
24
+ markerStoreConfig: {
25
+ data: [{
26
+ id : '1',
27
+ position: {lat: -34.397, lng: 150.644},
28
+ title : 'Hello neo'
29
+ }]
30
+ }
22
31
  }, {
23
32
  module: Toolbar,
24
33
  flex : 'none',
@@ -26,8 +35,28 @@ class MainContainer extends Viewport {
26
35
  items : [{
27
36
  module : Button,
28
37
  handler: 'onFlyToButtonClick',
38
+ height : 27,
29
39
  iconCls: 'fa-solid fa-plane',
30
40
  text : 'Fly to San Fran'
41
+ }, {
42
+ module : NumberField,
43
+ clearToOriginalValue: true,
44
+ labelPosition : 'inline',
45
+ labelText : 'zoom',
46
+ listeners : {change: 'onZoomFieldChange'},
47
+ minValue : 0,
48
+ maxValue : 10,
49
+ style : {marginLeft: '10px'},
50
+ value : 8,
51
+ width : 100
52
+ }, {
53
+ module : Button,
54
+ handler: 'onRemoveMarkerButtonClick',
55
+ height : 27,
56
+ iconCls: 'fa-solid fa-trash',
57
+ mode : 'hide',
58
+ style : {marginLeft: '10px'},
59
+ text : 'Hide marker'
31
60
  }]
32
61
  }]
33
62
  }}
@@ -17,12 +17,40 @@ class MainContainerController extends ComponentController {
17
17
  * @param {Object} data
18
18
  */
19
19
  onFlyToButtonClick(data) {
20
- // todo
21
- /*this.getReference('google-maps-component').flyTo({
22
- destination: [-122.4175, 37.655, 400],
23
- heading : 0.0,
24
- pitch : -15.0
25
- });*/
20
+ this.getReference('google-maps-component').panTo({lat: 37.655, lng: -122.4175})
21
+ }
22
+
23
+ /**
24
+ * @param {Object} data
25
+ */
26
+ onRemoveMarkerButtonClick(data) {
27
+ let button = data.component,
28
+ map = this.getReference('google-maps-component');
29
+
30
+ if (button.mode === 'hide') {
31
+ button.set({
32
+ iconCls: 'fa fa-location-dot',
33
+ mode : 'show',
34
+ text : 'Show marker'
35
+ });
36
+
37
+ map.hideMarker('1')
38
+ } else {
39
+ button.set({
40
+ iconCls: 'fa-solid fa-trash',
41
+ mode : 'hide',
42
+ text : 'Hide marker'
43
+ });
44
+
45
+ map.showMarker('1')
46
+ }
47
+ }
48
+
49
+ /**
50
+ * @param {Object} data
51
+ */
52
+ onZoomFieldChange(data) {
53
+ this.getReference('google-maps-component').zoom = data.value;
26
54
  }
27
55
  }
28
56
 
@@ -2,6 +2,7 @@
2
2
  "appPath" : "examples/component/wrapper/googleMaps/app.mjs",
3
3
  "basePath" : "../../../../",
4
4
  "environment" : "development",
5
+ "googleMapsApiKey": "AIzaSyCRj-EPE3H7PCzZtYCmDzln6sj7uPCGohA",
5
6
  "mainPath" : "./Main.mjs",
6
7
  "mainThreadAddons": ["GoogleMaps", "Stylesheet"]
7
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neo.mjs",
3
- "version": "4.4.9",
3
+ "version": "4.4.11",
4
4
  "description": "The webworkers driven UI framework",
5
5
  "type": "module",
6
6
  "repository": {
@@ -52,6 +52,14 @@ const DefaultConfig = {
52
52
  * @type String
53
53
  */
54
54
  environment: 'dist/production',
55
+ /**
56
+ * In case you are using the GoogleMaps main thread addon, you can pass the API key here.
57
+ * @default ''
58
+ * @memberOf! module:Neo
59
+ * @name config.googleMapsApiKey
60
+ * @type String
61
+ */
62
+ googleMapsApiKey: '',
55
63
  /**
56
64
  * In case you are using the GoogleAnalytics main thread addon or useGoogleAnalytics: true,
57
65
  * you can change the gtag id here. Required for the online examples (gh pages)
@@ -974,8 +974,8 @@ class Base extends CoreBase {
974
974
 
975
975
  /**
976
976
  * Unregisters this instance from the ComponentManager
977
- * @param {Boolean} [updateParentVdom=false] true to remove the component from the parent vdom => real dom
978
- * @param {Boolean} [silent=false] true to update the vdom silently (useful for destroying multiple child items in a row)
977
+ * @param {Boolean} updateParentVdom=false true to remove the component from the parent vdom => real dom
978
+ * @param {Boolean} silent=false true to update the vdom silently (useful for destroying multiple child items in a row)
979
979
  * todo: unregister events
980
980
  */
981
981
  destroy(updateParentVdom=false, silent=false) {
@@ -169,7 +169,7 @@ class Splitter extends Component {
169
169
  if (resizeNext) {
170
170
  newSize = parentRect.width - newSize;
171
171
  } else {
172
- newSize -= size;
172
+ newSize += size;
173
173
  }
174
174
 
175
175
  newSize = Math.min(Math.max(newSize, 0), parentRect.width - size);
@@ -1,4 +1,6 @@
1
- import Base from '../../component/Base.mjs';
1
+ import Base from '../../component/Base.mjs';
2
+ import ClassSystemUtil from '../../util/ClassSystem.mjs';
3
+ import Store from '../../data/Store.mjs';
2
4
 
3
5
  /**
4
6
  * @class Neo.component.wrapper.GoogleMaps
@@ -12,12 +14,108 @@ class GoogleMaps extends Base {
12
14
  */
13
15
  className: 'Neo.component.wrapper.GoogleMaps',
14
16
  /**
15
- * @member {Object} _vdom
17
+ * Specify lat & lng for the current focus position
18
+ * @member {Object} center_={lat: -34.397, lng: 150.644}
16
19
  */
17
- _vdom:
18
- {}
20
+ center_: {lat: -34.397, lng: 150.644},
21
+ /**
22
+ * false hides the default fullscreen control
23
+ * @member {Boolean} fullscreenControl=true
24
+ */
25
+ fullscreenControl: true,
26
+ /**
27
+ * Prefer to use markerStoreConfig instead.
28
+ * @member {Neo.data.Store|Object} markerStore_
29
+ * @protected
30
+ */
31
+ markerStore_: {
32
+ model: {
33
+ fields: [{
34
+ name: 'id',
35
+ type: 'String'
36
+ }, {
37
+ name: 'position',
38
+ type: 'Object'
39
+ }, {
40
+ name: 'title',
41
+ type: 'String'
42
+ }]
43
+ }
44
+ },
45
+ /**
46
+ * @member {Object} markerStoreConfig: null
47
+ */
48
+ markerStoreConfig: null,
49
+ /**
50
+ * null => the maximum zoom from the current map type is used instead
51
+ * @member {Number|null} maxZoom=null
52
+ */
53
+ maxZoom: null,
54
+ /**
55
+ null => the minimum zoom from the current map type is used instead
56
+ * @member {Number|null} minZoom=null
57
+ */
58
+ minZoom: null,
59
+ /**
60
+ * @member {Number} zoom_=8
61
+ */
62
+ zoom_: 8,
63
+ /**
64
+ * false hides the default zoom control
65
+ * @member {Boolean} zoomControl=true
66
+ */
67
+ zoomControl: true
19
68
  }}
20
69
 
70
+ /**
71
+ * @param {Object} data
72
+ * @param {String} data.id
73
+ * @param {String} data.mapId
74
+ * @param {Object} data.position
75
+ * @param {String} [data.title]
76
+ */
77
+ addMarker(data) {
78
+ Neo.main.addon.GoogleMaps.addMarker({
79
+ appName: this.appName,
80
+ ...data
81
+ });
82
+ }
83
+
84
+ /**
85
+ * Triggered after the center config got changed
86
+ * @param {Object} value
87
+ * @param {Object} oldValue
88
+ * @protected
89
+ */
90
+ afterSetCenter(value, oldValue) {
91
+ if (oldValue !== undefined) {
92
+ Neo.main.addon.GoogleMaps.setCenter({
93
+ appName: this.appName,
94
+ id : this.id,
95
+ value
96
+ })
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Triggered after the markerStore config got changed
102
+ * @param {Object} value
103
+ * @param {Object} oldValue
104
+ * @protected
105
+ */
106
+ afterSetMarkerStore(value, oldValue) {
107
+ let me = this;
108
+
109
+ value.on({
110
+ load : me.onMarkerStoreLoad,
111
+ scope: me
112
+ });
113
+
114
+ if (value.items.length > 0) {
115
+ me.onMarkerStoreLoad();
116
+ }
117
+ }
118
+
21
119
  /**
22
120
  * Triggered after the mounted config got changed
23
121
  * @param {Boolean} value
@@ -28,18 +126,21 @@ class GoogleMaps extends Base {
28
126
  let me = this;
29
127
 
30
128
  if (value === false && oldValue !== undefined) {
31
- Neo.main.addon.GoogleMaps.destroy({
32
- appName: me.appName,
33
- id : me.id
34
- });
129
+ me.removeMap();
35
130
  }
36
131
 
37
132
  super.afterSetMounted(value, oldValue);
38
133
 
39
134
  if (value) {
40
135
  let opts = {
41
- appName: me.appName,
42
- id : me.id
136
+ appName : me.appName,
137
+ center : me.center,
138
+ fullscreenControl: me.fullscreenControl,
139
+ id : me.id,
140
+ maxZoom : me.maxZoom,
141
+ minZoom : me.minZoom,
142
+ zoom : me.zoom,
143
+ zoomControl : me.zoomControl
43
144
  };
44
145
 
45
146
  setTimeout(() => {
@@ -50,11 +151,117 @@ class GoogleMaps extends Base {
50
151
  }
51
152
  }
52
153
 
154
+ /**
155
+ * Triggered after the zoom config got changed
156
+ * @param {Number} value
157
+ * @param {Number} oldValue
158
+ * @protected
159
+ */
160
+ afterSetZoom(value, oldValue) {
161
+ if (oldValue !== undefined) {
162
+ Neo.main.addon.GoogleMaps.setZoom({
163
+ appName: this.appName,
164
+ id : this.id,
165
+ value
166
+ })
167
+ }
168
+ }
169
+
170
+ /**
171
+ * Triggered before the markerStore config gets changed.
172
+ * @param {Object} value
173
+ * @param {Object} oldValue
174
+ * @protected
175
+ */
176
+ beforeSetMarkerStore(value, oldValue) {
177
+ oldValue?.destroy();
178
+
179
+ return ClassSystemUtil.beforeSetInstance(value, Store, this.markerStoreConfig);
180
+ }
181
+
182
+ /**
183
+ * @param {Boolean} updateParentVdom=false
184
+ * @param {Boolean} silent=false
185
+ */
186
+ destroy(updateParentVdom=false, silent=false) {
187
+ this.removeMap();
188
+ super.destroy(updateParentVdom, silent);
189
+ }
190
+
191
+ /**
192
+ * @param {String} id
193
+ */
194
+ hideMarker(id) {
195
+ Neo.main.addon.GoogleMaps.hideMarker({
196
+ appName: this.appName,
197
+ id,
198
+ mapId : this.id
199
+ })
200
+ }
201
+
202
+ /**
203
+ * Hook to use once the map instance got rendered
204
+ */
205
+ onComponentMounted() {}
206
+
53
207
  /**
54
208
  *
55
209
  */
56
- onComponentMounted() {
57
- console.log('onComponentMounted', this.id);
210
+ onMarkerStoreLoad() {
211
+ let me = this;
212
+
213
+ me.markerStore.items.forEach(item => {
214
+ Neo.main.addon.GoogleMaps.addMarker({
215
+ appName: me.appName,
216
+ mapId : me.id,
217
+ ...item
218
+ })
219
+ })
220
+ }
221
+
222
+ /**
223
+ * @param {Object} position
224
+ * @param {Number} position.lat
225
+ * @param {Number} position.lng
226
+ */
227
+ panTo(position) {
228
+ Neo.main.addon.GoogleMaps.panTo({
229
+ appName: this.appName,
230
+ mapId : this.id,
231
+ position
232
+ })
233
+ }
234
+
235
+ /**
236
+ *
237
+ */
238
+ removeMap() {
239
+ Neo.main.addon.GoogleMaps.removeMap({
240
+ appName: this.appName,
241
+ mapId : this.id
242
+ })
243
+ }
244
+
245
+ /**
246
+ * @param {String} id
247
+ */
248
+ removeMarker(id) {
249
+ Neo.main.addon.GoogleMaps.removeMarker({
250
+ appName: this.appName,
251
+ id,
252
+ mapId : this.id
253
+ })
254
+ }
255
+
256
+ /**
257
+ * @param {String} id
258
+ */
259
+ showMarker(id) {
260
+ Neo.main.addon.GoogleMaps.showMarker({
261
+ appName: this.appName,
262
+ id,
263
+ mapId : this.id
264
+ })
58
265
  }
59
266
  }
60
267
 
@@ -191,6 +191,16 @@ class Base extends Component {
191
191
  defaults = me.itemDefaults,
192
192
  lazyLoadItem, module;
193
193
 
194
+ if (defaults) {
195
+ if (item.module) {
196
+ delete defaults.ntype;
197
+ }
198
+
199
+ if (item.ntype) {
200
+ delete defaults.module;
201
+ }
202
+ }
203
+
194
204
  switch (Neo.typeOf(item)) {
195
205
  case 'NeoClass': {
196
206
  item = Neo.create({
@@ -1,5 +1,6 @@
1
- import Base from '../../core/Base.mjs';
2
- import DomAccess from '../DomAccess.mjs';
1
+ import Base from '../../core/Base.mjs';
2
+ import DomAccess from '../DomAccess.mjs';
3
+ import Observable from '../../core/Observable.mjs';
3
4
 
4
5
  /**
5
6
  * @class Neo.main.addon.GoogleMaps
@@ -17,13 +18,29 @@ class GoogleMaps extends Base {
17
18
  * @member {Object} maps={}
18
19
  */
19
20
  maps: {},
21
+ /**
22
+ * @member {Object} markers={}
23
+ */
24
+ markers: {},
25
+ /**
26
+ * @member {Neo.core.Base[]} mixins=[Observable]
27
+ */
28
+ mixins: [Observable],
20
29
  /**
21
30
  * @member {Object} remote
22
31
  * @protected
23
32
  */
24
33
  remote: {
25
34
  app: [
26
- 'create'
35
+ 'addMarker',
36
+ 'create',
37
+ 'hideMarker',
38
+ 'panTo',
39
+ 'removeMap',
40
+ 'removeMarker',
41
+ 'setCenter',
42
+ 'setZoom',
43
+ 'showMarker'
27
44
  ]
28
45
  },
29
46
  /**
@@ -44,21 +61,131 @@ class GoogleMaps extends Base {
44
61
  /**
45
62
  * @param {Object} data
46
63
  * @param {String} data.id
64
+ * @param {String} data.mapId
65
+ * @param {Object} data.position
66
+ * @param {String} [data.title]
67
+ */
68
+ addMarker(data) {
69
+ let me = this;
70
+
71
+ if (!me.maps[data.mapId]) {
72
+ let listenerId = me.on('mapCreated', mapId => {
73
+ if (data.mapId === mapId) {
74
+ me.un(listenerId);
75
+ me.addMarker(data);
76
+ }
77
+ })
78
+ } else {
79
+ Neo.ns(`${data.mapId}`, true, me.markers);
80
+
81
+ me.markers[data.mapId][data.id] = new google.maps.Marker({
82
+ position: data.position,
83
+ map : me.maps[data.mapId],
84
+ title : data.title,
85
+ });
86
+ }
87
+ }
88
+
89
+ /**
90
+ * @param {Object} data
91
+ * @param {Object} data.center
92
+ * @param {Boolean} data.fullscreenControl
93
+ * @param {String} data.id
94
+ * @param {Number} data.maxZoom
95
+ * @param {Number} data.minZoom
96
+ * @param {Number} data.zoom
97
+ * @param {Boolean} data.zoomControl
47
98
  */
48
99
  create(data) {
49
- this.maps[data.id] = new google.maps.Map(DomAccess.getElement(data.id), {
50
- center: { lat: -34.397, lng: 150.644 },
51
- zoom: 8,
100
+ let me = this;
101
+
102
+ me.maps[data.id] = new google.maps.Map(DomAccess.getElement(data.id), {
103
+ center : data.center,
104
+ fullscreenControl: data.fullscreenControl,
105
+ maxZoom : data.maxZoom,
106
+ minZoom : data.minZoom,
107
+ zoom : data.zoom,
108
+ zoomControl : data.zoomControl
52
109
  });
110
+
111
+ me.fire('mapCreated', data.id);
112
+ }
113
+
114
+ /**
115
+ * @param {Object} data
116
+ * @param {String} data.id
117
+ * @param {String} data.mapId
118
+ */
119
+ hideMarker(data) {
120
+ this.markers[data.mapId][data.id].setMap(null);
53
121
  }
54
122
 
55
123
  /**
56
124
  * @protected
57
125
  */
58
126
  loadApi() {
59
- DomAccess.loadScript('https://maps.googleapis.com/maps/api/js?key=AIzaSyCRj-EPE3H7PCzZtYCmDzln6sj7uPCGohA&v=weekly').then(() => {
127
+ let key = Neo.config.googleMapsApiKey;
128
+
129
+ DomAccess.loadScript(`https://maps.googleapis.com/maps/api/js?key=${key}&v=weekly`).then(() => {
60
130
  console.log('GoogleMaps API loaded');
61
- });
131
+ })
132
+ }
133
+
134
+ /**
135
+ * @param data
136
+ * @param {String} data.mapId
137
+ * @param {Object} data.position
138
+ */
139
+ panTo(data) {
140
+ this.maps[data.mapId].panTo(data.position);
141
+ }
142
+
143
+ /**
144
+ * @param {Object} data
145
+ * @param {String} data.mapId
146
+ */
147
+ removeMap(data) {
148
+ delete this.maps[data.mapId];
149
+ delete this.markers[data.mapId];
150
+ }
151
+
152
+ /**
153
+ * @param {Object} data
154
+ * @param {String} data.id
155
+ * @param {String} data.mapId
156
+ */
157
+ removeMarker(data) {
158
+ let markers = this.markers[data.mapId];
159
+
160
+ markers[data.id].setMap(null);
161
+ delete markers[data.id];
162
+ }
163
+
164
+ /**
165
+ * @param {Object} data
166
+ * @param {String} data.id
167
+ * @param {Object} data.value
168
+ */
169
+ setCenter(data) {
170
+ this.maps[data.id].setCenter(data.value);
171
+ }
172
+
173
+ /**
174
+ * @param {Object} data
175
+ * @param {String} data.id
176
+ * @param {Number} data.value
177
+ */
178
+ setZoom(data) {
179
+ this.maps[data.id].setZoom(data.value);
180
+ }
181
+
182
+ /**
183
+ * @param {Object} data
184
+ * @param {String} data.id
185
+ * @param {String} data.mapId
186
+ */
187
+ showMarker(data) {
188
+ this.markers[data.mapId][data.id].setMap(this.maps[data.mapId]);
62
189
  }
63
190
  }
64
191
 
@@ -184,11 +184,15 @@ class Component extends Base {
184
184
  }
185
185
 
186
186
  /**
187
- * Returns an Array containing all parent components for a given component
188
- * @param {Neo.component.Base} component
187
+ * Returns an Array containing all parent components for a given component or component id
188
+ * @param {Neo.component.Base|String} component
189
189
  * @returns {Neo.component.Base[]} parents
190
190
  */
191
191
  getParents(component) {
192
+ if (Neo.isString(component)) {
193
+ component = this.getById(component);
194
+ }
195
+
192
196
  let parents = [];
193
197
 
194
198
  while (component?.parentId) {