@vcmap/ui 5.0.0-rc.12 → 5.0.0-rc.13

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 (37) hide show
  1. package/README.md +1 -1
  2. package/dist/assets/{cesium.4057e6.js → cesium.21663e.js} +0 -0
  3. package/dist/assets/cesium.js +1 -1
  4. package/dist/assets/{core.deb2b7.js → core.63242d.js} +1 -1
  5. package/dist/assets/core.js +1 -1
  6. package/dist/assets/{index.7aa11f5a.js → index.44b91cfe.js} +1 -1
  7. package/dist/assets/{ol.70b137.js → ol.88ba9d.js} +0 -0
  8. package/dist/assets/ol.js +1 -1
  9. package/dist/assets/ui.3c2933.css +1 -0
  10. package/dist/assets/{ui.9eb282.js → ui.3c2933.js} +43 -42
  11. package/dist/assets/ui.js +1 -1
  12. package/dist/assets/{vue.65d93f.js → vue.c897fc.js} +0 -0
  13. package/dist/assets/vue.js +2 -2
  14. package/dist/assets/{vuetify.149dde.css → vuetify.147c3a.css} +0 -0
  15. package/dist/assets/{vuetify.149dde.js → vuetify.147c3a.js} +1 -1
  16. package/dist/assets/vuetify.js +2 -2
  17. package/dist/index.html +1 -1
  18. package/index.js +1 -0
  19. package/package.json +12 -2
  20. package/plugins/example/index.js +10 -23
  21. package/plugins/test/index.js +13 -4
  22. package/plugins/test/toolbox-data.js +82 -57
  23. package/src/application/VcsApp.vue +1 -1
  24. package/src/components/lists/VcsActionList.vue +13 -7
  25. package/src/featureInfo/BalloonComponent.vue +2 -0
  26. package/src/featureInfo/featureInfo.js +5 -3
  27. package/src/i18n/de.js +4 -0
  28. package/src/i18n/en.js +4 -0
  29. package/src/manager/buttonManager.js +2 -7
  30. package/src/manager/navbarManager.js +1 -1
  31. package/src/manager/toolbox/GroupToolboxComponent.vue +118 -0
  32. package/src/manager/toolbox/SelectToolboxComponent.vue +128 -0
  33. package/src/manager/toolbox/ToolboxManager.vue +116 -99
  34. package/src/manager/toolbox/toolboxManager.js +233 -88
  35. package/src/vcsUiApp.js +1 -1
  36. package/dist/assets/ui.9eb282.css +0 -1
  37. package/src/manager/toolbox/ToolboxGroupComponent.vue +0 -132
@@ -1,73 +1,176 @@
1
- /* eslint-disable import/prefer-default-export */
2
1
  import { VcsEvent } from '@vcmap/core';
3
2
  import { check, checkMaybe } from '@vcsuite/check';
4
3
  import { v4 as uuidv4 } from 'uuid';
4
+ import { reactive } from 'vue';
5
+ import { vcsAppSymbol } from '../../pluginHelper.js';
5
6
  import ButtonManager from '../buttonManager.js';
7
+ import { ActionPattern } from '../../components/lists/VcsActionList.vue';
6
8
 
7
9
  /**
8
- * @typedef ToolboxGroupComponentOptions
9
- * @property {string} [id] Optional ID, If not provided an uuid will be generated.
10
- * @property {string} [icon] Optional group icon, for dropdowns
11
- * @property {string} [title] Optional group title, for dropdowns
10
+ * Possible group types. Define behaviour of group:
11
+ * @property {number} SINGLE - SingleToolboxComponent with single toggle action rendered as VcsButton
12
+ * @property {number} SELECT - SelectToolboxComponent with one selected item of a list of items
13
+ * @property {number} GROUP - GroupToolboxComponent with multiple non-exclusive items rendered as VcsButton
14
+ * @enum {number}
12
15
  */
16
+ export const ToolboxType = {
17
+ SINGLE: 0,
18
+ SELECT: 1,
19
+ GROUP: 2,
20
+ };
13
21
 
14
22
  /**
15
- * @typedef ToolboxGroupComponent
23
+ * @typedef {Object} ToolboxComponentOptions
24
+ * @property {string} [id] - Optional ID, If not provided an uuid will be generated.
25
+ * @property {ToolboxType} type - Group type, defining the behaviour of the group
26
+ */
27
+
28
+ /**
29
+ * @typedef {ToolboxComponentOptions} SingleToolboxComponentOptions
30
+ * @property {VcsAction} action - An action of a single tool
31
+ */
32
+
33
+ /**
34
+ * @typedef {ToolboxComponentOptions} SelectToolboxComponentOptions
35
+ * @property {ToolboxSelectAction} action - An action determining the behaviour of the select group
36
+ */
37
+
38
+ /**
39
+ * @typedef {ToolboxComponentOptions} GroupToolboxComponentOptions
40
+ * @property {string} icon - Group icon
41
+ * @property {string} [title] - Optional group title, for dropdown
42
+ */
43
+
44
+ /**
45
+ * @typedef {Object} ToolboxComponent
16
46
  * @property {string} id
17
- * @property {string} title
47
+ * @property {ToolboxType} type - Group type, defining the behaviour of the group
48
+ * @property {string|vcsAppSymbol} owner
49
+ */
50
+
51
+ /**
52
+ * @typedef {ToolboxComponent} SingleToolboxComponent
53
+ * @property {VcsAction} action
54
+ */
55
+
56
+ /**
57
+ * @typedef {ToolboxComponent} GroupToolboxComponent
58
+ * @property {string|undefined} icon
59
+ * @property {string|undefined} title
18
60
  * @property {ButtonManager} buttonManager
19
61
  */
20
62
 
63
+ /**
64
+ * @typedef {ToolboxComponent} SelectToolboxComponent
65
+ * @property {ToolboxSelectAction} action
66
+ */
67
+
68
+ /**
69
+ * @typedef {VcsAction} ToolboxSelectAction
70
+ * @property {function(index:number):void} selected - A callback determining the select behavior of the group. Should set the currentIndex.
71
+ * @property {Array<ToolboxSelectItem>} tools - A list of exclusive tools belonging to the group
72
+ * @property {number} currentIndex - Index of the current item
73
+ */
74
+
75
+ /**
76
+ * @typedef {Object} ToolboxSelectItem
77
+ * @property {string} name
78
+ * @property {string} [title]
79
+ * @property {string} icon
80
+ */
81
+
21
82
  /**
22
83
  * Default groups predefining icon and title of the group
23
- * @type {Array<ToolboxGroupComponentOptions>}
84
+ * @type {Array<ToolboxComponentOptions>}
24
85
  */
25
86
  const defaultGroups = [
26
- {
27
- id: 'featureInfo',
28
- icon: '$vcsInfo',
29
- title: 'Feature Info',
30
- },
31
- {
32
- id: 'select',
33
- icon: '$vcsPen',
34
- title: 'select',
35
- },
36
- {
37
- id: 'measurement',
38
- icon: '$vcsDimensionsHouse',
39
- title: 'measurement',
40
- },
41
87
  {
42
88
  id: 'flight',
89
+ type: ToolboxType.GROUP,
43
90
  icon: '$vcsVideoRecorder',
44
- title: 'flight',
91
+ title: 'toolbox.flight',
92
+ },
93
+ {
94
+ id: 'miscellaneous',
95
+ type: ToolboxType.GROUP,
96
+ icon: 'mdi-dots-grid',
97
+ title: 'toolbox.miscellaneous',
45
98
  },
46
99
  ];
47
100
 
48
101
  /**
49
- * Requests default groups for a toolboxManager.
102
+ * Default order of toolboxComponents shown in the toolbox
103
+ * @type {string[]}
104
+ */
105
+ const defaultOrder = ['featureInfo', 'flight'];
106
+
107
+ /**
108
+ * sorts by owner and optionally plugin order
109
+ * If both components are owned by vcsApp, defaultOrder is used to compare
110
+ * @param {ToolboxComponent|ButtonComponent} compA
111
+ * @param {ToolboxComponent|ButtonComponent} compB
112
+ * @param {string[]} [order] order of owners to sort by
113
+ * @returns {number}
114
+ */
115
+ export function sortByOwner(compA, compB, order = []) {
116
+ const sorted = [vcsAppSymbol, ...order];
117
+ let indexA = sorted.indexOf(compA.owner);
118
+ let indexB = sorted.indexOf(compB.owner);
119
+
120
+ if (compA.owner === vcsAppSymbol && compB.owner === vcsAppSymbol) {
121
+ indexA = defaultOrder.indexOf(compA.id);
122
+ indexB = defaultOrder.indexOf(compB.id);
123
+ }
124
+
125
+ if (indexA === indexB) {
126
+ return 0;
127
+ }
128
+
129
+ if (indexA === -1) {
130
+ return 1;
131
+ }
132
+
133
+ if (indexB === -1) {
134
+ return -1;
135
+ }
136
+ return indexA - indexB;
137
+ }
138
+
139
+ /**
140
+ * returns ToolboxComponents sorted by owner (or other sort function)
141
+ * @param {Array<ToolboxComponent|ButtonComponent>} components
142
+ * @param {string[]} [order] optional order to sort by (plugin names)
143
+ * @param {function(ownerA:string, ownerB:string, order: string[]):number} [compareFn=sortByOwner] Per default components are sorted by owner: app first, then plugins
144
+ * @returns {Array<ToolboxComponent|ButtonComponent>}
145
+ */
146
+ export function getComponentsByOrder(components, order = [], compareFn = sortByOwner) {
147
+ return [...components]
148
+ .sort((a, b) => compareFn(a, b, order));
149
+ }
150
+
151
+ /**
152
+ * Adds default groups for a toolboxManager.
50
153
  * Once requested, group id, icon and title are defined and cannot be changed or overwritten.
51
154
  * @param {ToolboxManager} toolboxManager
52
- * @param {Array<ToolboxGroupComponentOptions>} groups
155
+ * @param {Array<ToolboxComponentOptions>} groups
53
156
  */
54
157
  export function setupDefaultGroups(toolboxManager, groups = defaultGroups) {
55
- groups.forEach(({ id, icon, title }) => toolboxManager.requestGroup(id, icon, title));
158
+ groups.forEach(toolboxComponentOptions => toolboxManager.add(toolboxComponentOptions, vcsAppSymbol));
56
159
  }
57
160
 
58
161
  /**
59
162
  * @class ToolboxManager
60
- * @description Manages a set of Toolbox Groups
61
- * @implements VcsComponentManager<ToolboxGroupComponent,ToolboxGroupComponentOptions>
163
+ * @description Manages a set of Toolbox Components
164
+ * @implements VcsComponentManager<ToolboxComponent,ToolboxComponentOptions>
62
165
  */
63
- export class ToolboxManager {
166
+ class ToolboxManager {
64
167
  constructor() {
65
168
  /**
66
- * @type {import("@vcmap/core").VcsEvent<ToolboxGroupComponent>}
169
+ * @type {import("@vcmap/core").VcsEvent<ToolboxComponent>}
67
170
  */
68
171
  this.added = new VcsEvent();
69
172
  /**
70
- * @type {import("@vcmap/core").VcsEvent<ToolboxGroupComponent>}
173
+ * @type {import("@vcmap/core").VcsEvent<ToolboxComponent>}
71
174
  */
72
175
  this.removed = new VcsEvent();
73
176
  /**
@@ -77,7 +180,7 @@ export class ToolboxManager {
77
180
  this.componentIds = [];
78
181
 
79
182
  /**
80
- * @type {Map<string, ToolboxGroupComponent>}
183
+ * @type {Map<string, ToolboxComponent>}
81
184
  * @private
82
185
  */
83
186
  this._toolboxGroups = new Map();
@@ -85,7 +188,7 @@ export class ToolboxManager {
85
188
 
86
189
  /**
87
190
  * @param {string} id
88
- * @returns {ToolboxGroupComponent}
191
+ * @returns {ToolboxComponent}
89
192
  */
90
193
  get(id) {
91
194
  return this._toolboxGroups.get(id);
@@ -100,95 +203,135 @@ export class ToolboxManager {
100
203
  }
101
204
 
102
205
  /**
103
- * Toolbox groups should be static. Removing them can lead to undefined behavior.
206
+ * removes a ToolboxComponent, Component will not be rendered anymore and will be destroyed.
207
+ * Add ToolboxComponent again to show the component again
104
208
  * @param {string} id
105
209
  */
106
210
  remove(id) {
107
211
  check(id, String);
108
- const toolboxGroupComponent = this._toolboxGroups.get(id);
109
- if (toolboxGroupComponent) {
212
+ const toolboxComponent = this._toolboxGroups.get(id);
213
+ if (toolboxComponent) {
110
214
  const index = this.componentIds.indexOf(id);
111
215
  this.componentIds.splice(index, 1);
112
216
  this._toolboxGroups.delete(id);
113
- this.removed.raiseEvent(toolboxGroupComponent);
114
- toolboxGroupComponent.buttonManager.destroy();
217
+ this.removed.raiseEvent(toolboxComponent);
218
+ if (toolboxComponent.buttonManager) {
219
+ toolboxComponent.buttonManager.destroy();
220
+ }
115
221
  }
116
222
  }
117
223
 
118
224
  /**
119
- * Do not call add directly. Use requestGroup for adding toolbox groups.
120
- * @param {ToolboxGroupComponentOptions} toolboxGroupComponentOptions
121
- * @throws {Error} if a buttonComponent with the same ID has already been added
122
- * @returns {ToolboxGroupComponent}
225
+ * adds a ToolboxComponent
226
+ * @param {SingleToolboxComponentOptions|SelectToolboxComponentOptions|GroupToolboxComponentOptions} toolboxComponentOptions
227
+ * @param {string|symbol} owner pluginName or vcsAppSymbol
228
+ * @throws {Error} if a toolboxComponent with the same ID has already been added
229
+ * @returns {SingleToolboxComponent|SelectToolboxComponent|GroupToolboxComponent}
123
230
  */
124
- add(toolboxGroupComponentOptions) {
125
- checkMaybe(toolboxGroupComponentOptions.id, String);
126
- checkMaybe(toolboxGroupComponentOptions.icon, String);
127
- checkMaybe(toolboxGroupComponentOptions.title, String);
231
+ add(toolboxComponentOptions, owner) {
232
+ checkMaybe(toolboxComponentOptions.id, String);
233
+ check(toolboxComponentOptions.type, Object.values(ToolboxType));
234
+ check(owner, [String, vcsAppSymbol]);
128
235
 
129
- if (toolboxGroupComponentOptions.id && this.has(toolboxGroupComponentOptions.id)) {
130
- throw new Error(`A toolGroup with id ${toolboxGroupComponentOptions.id} has already been registered.`);
236
+ if (toolboxComponentOptions.id && this.has(toolboxComponentOptions.id)) {
237
+ throw new Error(`A toolGroup with id ${toolboxComponentOptions.id} has already been registered.`);
131
238
  }
132
- const id = toolboxGroupComponentOptions.id || uuidv4();
133
- const icon = toolboxGroupComponentOptions.icon || undefined;
134
- const title = toolboxGroupComponentOptions.title || undefined;
135
- const buttonManager = new ButtonManager();
239
+ const id = toolboxComponentOptions.id || uuidv4();
240
+ const { type } = toolboxComponentOptions;
136
241
 
137
242
  /**
138
- * @type {ToolboxGroupComponent}
243
+ * @type {ToolboxComponent}
139
244
  */
140
- const toolboxGroupComponent = {
245
+ let toolboxComponent = {
141
246
  get id() {
142
247
  return id;
143
248
  },
144
- get icon() {
145
- return icon;
146
- },
147
- get title() {
148
- return title;
249
+ get type() {
250
+ return type;
149
251
  },
150
- get buttonManager() {
151
- return buttonManager;
252
+ get owner() {
253
+ return owner;
152
254
  },
153
255
  };
154
256
 
155
- this._toolboxGroups.set(id, toolboxGroupComponent);
156
- this.componentIds.push(id);
157
- this.added.raiseEvent(toolboxGroupComponent);
158
- return toolboxGroupComponent;
159
- }
160
-
161
- /**
162
- * Returns an existing group or creates a new group. Add toolbox groups with this API.
163
- * @param {string} id
164
- * @param {string} [icon='mdi-select-group']
165
- * @param {string} [title='defaultGroup']
166
- * @returns {ToolboxGroupComponent}
167
- */
168
- requestGroup(id, icon = 'mdi-select-group', title = 'defaultGroup') {
169
- check(id, String);
170
- checkMaybe(icon, String);
171
- checkMaybe(title, String);
172
-
173
- if (this.has(id)) {
174
- return this.get(id);
257
+ if (type === ToolboxType.SINGLE) {
258
+ check(toolboxComponentOptions.action, ActionPattern);
259
+ /**
260
+ * @type {SingleToolboxComponent}
261
+ */
262
+ toolboxComponent = {
263
+ ...toolboxComponent,
264
+ get action() {
265
+ return reactive(toolboxComponentOptions.action);
266
+ },
267
+ };
268
+ } else if (type === ToolboxType.SELECT) {
269
+ check(toolboxComponentOptions.action, {
270
+ ...ActionPattern,
271
+ selected: Function,
272
+ currentIndex: Number,
273
+ tools: [{
274
+ name: String,
275
+ title: [undefined, String],
276
+ icon: String,
277
+ }],
278
+ });
279
+ /**
280
+ * @type {SelectToolboxComponent}
281
+ */
282
+ toolboxComponent = {
283
+ ...toolboxComponent,
284
+ get action() {
285
+ return reactive(toolboxComponentOptions.action);
286
+ },
287
+ };
175
288
  } else {
176
- return this.add({ id, icon, title });
289
+ check(toolboxComponentOptions.icon, String);
290
+ checkMaybe(toolboxComponentOptions.title, String);
291
+ const { icon, title = undefined } = toolboxComponentOptions;
292
+ const buttonManager = new ButtonManager();
293
+ /**
294
+ * @type {GroupToolboxComponent}
295
+ */
296
+ toolboxComponent = {
297
+ ...toolboxComponent,
298
+ get icon() {
299
+ return icon;
300
+ },
301
+ get title() {
302
+ return title;
303
+ },
304
+ get buttonManager() {
305
+ return buttonManager;
306
+ },
307
+ };
177
308
  }
309
+
310
+ this._toolboxGroups.set(toolboxComponent.id, toolboxComponent);
311
+ this.componentIds.push(toolboxComponent.id);
312
+ this.added.raiseEvent(toolboxComponent);
313
+ return toolboxComponent;
178
314
  }
179
315
 
180
316
  /**
181
- * removes all {@link ButtonComponent}s of a specific owner and fires removed Events
317
+ * removes all {@link ToolboxComponent}s of a specific owner and fires removed Events
182
318
  * @param {string|vcsAppSymbol} owner
183
319
  */
184
320
  removeOwner(owner) {
185
- this.componentIds.forEach((id) => {
186
- this.get(id).buttonManager.removeOwner(owner);
321
+ const componentIds = [...this.componentIds];
322
+ componentIds.forEach((id) => {
323
+ const toolboxComponent = this.get(id);
324
+ if (toolboxComponent.buttonManager) {
325
+ toolboxComponent.buttonManager.removeOwner(owner);
326
+ }
327
+ if (owner === toolboxComponent.owner) {
328
+ this.remove(id);
329
+ }
187
330
  });
188
331
  }
189
332
 
190
333
  /**
191
- * removes all buttonComponents and fires removed Events
334
+ * removes all toolboxComponents and fires removed Events
192
335
  */
193
336
  clear() {
194
337
  const componentIds = [...this.componentIds];
@@ -196,7 +339,7 @@ export class ToolboxManager {
196
339
  }
197
340
 
198
341
  /**
199
- * destroys the ButtonManager;
342
+ * destroys the ToolboxManager;
200
343
  */
201
344
  destroy() {
202
345
  this.added.destroy();
@@ -206,3 +349,5 @@ export class ToolboxManager {
206
349
  this._toolboxGroups.clear();
207
350
  }
208
351
  }
352
+
353
+ export default ToolboxManager;
package/src/vcsUiApp.js CHANGED
@@ -17,7 +17,7 @@ import {
17
17
  serializePlugin,
18
18
  deserializePlugin,
19
19
  } from './pluginHelper.js';
20
- import { setupDefaultGroups, ToolboxManager } from './manager/toolbox/toolboxManager.js';
20
+ import ToolboxManager, { setupDefaultGroups } from './manager/toolbox/toolboxManager.js';
21
21
  import { WindowManager } from './manager/window/windowManager.js';
22
22
  import { NavbarManager } from './manager/navbarManager.js';
23
23
  import { createContentTreeCollection } from './contentTree/contentTreeCollection.js';