@vcmap/module-selector 3.0.0 → 4.0.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.
@@ -1,53 +1,43 @@
1
1
  <template>
2
2
  <v-container class="py-0 px-1">
3
3
  <v-row
4
- no-gutters
5
4
  v-for="{ key, checkbox, input, placeholder } in inputs"
6
5
  :key="key"
6
+ no-gutters
7
7
  >
8
8
  <v-col>
9
9
  <VcsCheckbox
10
- :label="`appConfigurator.editors.featureInfo.window.position.${key}`"
11
10
  v-model="checkbox.value"
11
+ :label="`appConfigurator.editors.featureInfo.window.position.${key}`"
12
12
  />
13
13
  </v-col>
14
14
  <v-col>
15
15
  <VcsTextField
16
+ v-model.trim="input.value"
16
17
  clearable
17
18
  :disabled="!checkbox.value"
18
19
  :placeholder="placeholder"
19
- v-model.trim="input.value"
20
20
  />
21
21
  </v-col>
22
22
  </v-row>
23
23
  </v-container>
24
24
  </template>
25
+
25
26
  <script lang="ts">
26
- import {
27
- computed,
28
- defineComponent,
29
- PropType,
30
- Ref,
31
- WritableComputedRef,
32
- } from 'vue';
27
+ import type { PropType, WritableComputedRef } from 'vue';
28
+ import { computed, defineComponent } from 'vue';
33
29
  import { VContainer, VRow, VCol } from 'vuetify/components';
30
+ import type { WindowPositionOptions } from '@vcmap/ui';
34
31
  import {
35
32
  useModelHasProperty,
36
33
  useProxiedComplexModel,
37
34
  VcsCheckbox,
38
35
  VcsTextField,
39
- WindowPositionOptions,
40
36
  } from '@vcmap/ui';
41
37
 
42
38
  export default defineComponent({
43
39
  name: 'WindowPositionSettings',
44
- components: {
45
- VContainer,
46
- VRow,
47
- VCol,
48
- VcsCheckbox,
49
- VcsTextField,
50
- },
40
+ components: { VContainer, VRow, VCol, VcsCheckbox, VcsTextField },
51
41
  props: {
52
42
  modelValue: {
53
43
  type: Object as PropType<WindowPositionOptions>,
@@ -59,7 +49,7 @@
59
49
  },
60
50
  },
61
51
  setup(props, { emit }) {
62
- const localValue: Ref<WindowPositionOptions> = useProxiedComplexModel(
52
+ const localValue = useProxiedComplexModel<WindowPositionOptions>(
63
53
  props,
64
54
  'modelValue',
65
55
  emit,
@@ -83,6 +73,7 @@
83
73
  };
84
74
  return acc;
85
75
  },
76
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
86
77
  {} as Record<
87
78
  keyof WindowPositionOptions,
88
79
  {
@@ -95,9 +86,7 @@
95
86
  );
96
87
  });
97
88
 
98
- return {
99
- inputs,
100
- };
89
+ return { inputs };
101
90
  },
102
91
  });
103
92
  </script>
@@ -1,9 +1,8 @@
1
1
  import { authorize, setServerUrl } from '@vcsuite/publisher-sdk';
2
2
  import { getLogger } from '@vcsuite/logger';
3
3
  import { name } from '../../package.json';
4
- import { ModuleSelectorConfig } from '../index';
4
+ import type { ModuleSelectorConfig } from '../index';
5
5
 
6
- // eslint-disable-next-line import/prefer-default-export
7
6
  export function setupPublisherSDK(options: ModuleSelectorConfig): void {
8
7
  try {
9
8
  if (options.serverUrl) {
@@ -1,4 +1,4 @@
1
- import { ModuleSelectorConfig } from './index.js';
1
+ import type { ModuleSelectorConfig } from './index.js';
2
2
 
3
3
  export default (): ModuleSelectorConfig => ({
4
4
  windowTitle: 'moduleSelector.title',
package/src/index.ts CHANGED
@@ -1,26 +1,25 @@
1
- import {
2
- ButtonLocation,
3
- createToggleAction,
1
+ import type {
4
2
  PluginConfigEditor,
5
3
  VcsPlugin,
6
4
  VcsUiApp,
7
5
  WindowPositionOptions,
8
- WindowSlot,
9
6
  } from '@vcmap/ui';
10
- import { Ref, ref } from 'vue';
7
+ import { ButtonLocation, createToggleAction, WindowSlot } from '@vcmap/ui';
8
+ import type { Ref } from 'vue';
9
+ import { ref } from 'vue';
11
10
  import { parseBoolean, parseInteger } from '@vcsuite/parsers';
12
11
  import equal from 'fast-deep-equal';
13
12
  import { mapVersion, name, version } from '../package.json';
14
13
  import moduleSelector from './ModuleSelector.vue';
15
14
  import getDefaultOptions from './defaultOptions.js';
16
15
  import ModuleSelectorConfigEditor from './config/ModuleSelectorConfigEditor.vue';
17
- import { startApplication, windowIdModuleSelector } from './moduleHelper';
16
+ import {
17
+ loadModule,
18
+ unloadModule,
19
+ windowIdModuleSelector,
20
+ } from './moduleHelper';
18
21
 
19
- export type BasisModule = {
20
- title: string;
21
- icon: string;
22
- description?: string;
23
- };
22
+ export type BasisModule = { title: string; icon: string; description?: string };
24
23
 
25
24
  export type ModuleType = 'group' | 'url';
26
25
 
@@ -60,12 +59,17 @@ export type ModuleSelectorPlugin = VcsPlugin<
60
59
  readonly config: ModuleSelectorConfig;
61
60
  selectedMainModuleIndex: Ref<number | undefined | null>;
62
61
  selectedNestedModuleIndex: Ref<number | undefined | null>;
62
+ startApplication(
63
+ mainModuleIndex: number | undefined | null,
64
+ nestedModuleIndex: number | undefined | null,
65
+ ): Promise<void>;
63
66
  };
64
67
 
65
68
  export default function plugin(
66
69
  configInput: ModuleSelectorConfig,
67
70
  ): ModuleSelectorPlugin {
68
71
  let app: VcsUiApp;
72
+ let moduleId: string | undefined;
69
73
  return {
70
74
  get name(): string {
71
75
  return name;
@@ -77,7 +81,30 @@ export default function plugin(
77
81
  return mapVersion;
78
82
  },
79
83
  get config(): ModuleSelectorConfig {
80
- return { ...getDefaultOptions(), ...configInput } as ModuleSelectorConfig;
84
+ return { ...getDefaultOptions(), ...configInput };
85
+ },
86
+ async startApplication(
87
+ mainModuleIndex: number | undefined | null,
88
+ nestedModuleIndex: number | undefined | null,
89
+ ): Promise<void> {
90
+ await unloadModule(app, moduleId);
91
+ moduleId = undefined;
92
+
93
+ if (mainModuleIndex === null && !this.config.basisModule) {
94
+ app.windowManager.remove(windowIdModuleSelector);
95
+ return;
96
+ }
97
+
98
+ const mainModule = this.config.modules?.[mainModuleIndex!];
99
+ const moduleUrl =
100
+ mainModule?.type === 'group'
101
+ ? mainModule.cards?.[nestedModuleIndex!]?.moduleUrl
102
+ : mainModule?.moduleUrl;
103
+
104
+ if (moduleUrl) {
105
+ moduleId = await loadModule(moduleUrl, app);
106
+ }
107
+ app.windowManager.remove(windowIdModuleSelector);
81
108
  },
82
109
  selectedMainModuleIndex: ref(undefined),
83
110
  selectedNestedModuleIndex: ref(undefined),
@@ -124,12 +151,9 @@ export default function plugin(
124
151
  }
125
152
 
126
153
  if (!w) {
127
- await startApplication(
154
+ await this.startApplication(
128
155
  this.selectedMainModuleIndex.value,
129
156
  this.selectedNestedModuleIndex.value,
130
- app,
131
- this.config.modules,
132
- this.config.basisModule,
133
157
  );
134
158
  }
135
159
  }
@@ -146,10 +170,7 @@ export default function plugin(
146
170
  );
147
171
 
148
172
  app.navbarManager.add(
149
- {
150
- id: action.name,
151
- action,
152
- },
173
+ { id: action.name, action },
153
174
  name,
154
175
  ButtonLocation.PROJECT,
155
176
  { desktop: true, tablet: true, mobile: true },
@@ -1,12 +1,10 @@
1
- // eslint-disable-next-line import/prefer-default-export
2
1
  import { VcsModule } from '@vcmap/core';
3
- import { VcsUiApp } from '@vcmap/ui';
4
- import type { BasisModule, Module, ModuleType } from './index';
2
+ import type { VcsUiApp } from '@vcmap/ui';
5
3
 
6
4
  export async function loadModule(
7
5
  moduleUrl: string,
8
6
  app: VcsUiApp,
9
- ): Promise<void> {
7
+ ): Promise<string | undefined> {
10
8
  const config = await fetch(moduleUrl, {
11
9
  method: 'GET',
12
10
  }).then((response) => {
@@ -17,18 +15,23 @@ export async function loadModule(
17
15
  });
18
16
 
19
17
  if (config) {
20
- config._id = `moduleSelector_module_id`;
21
18
  const module = new VcsModule(config);
22
19
  await app.addModule(module);
20
+ return module._id;
23
21
  }
22
+ return undefined;
24
23
  }
25
24
 
26
- export async function unloadModule(app: VcsUiApp): Promise<void> {
27
- const moduleId = `moduleSelector_module_id`;
25
+ export async function unloadModule(
26
+ app: VcsUiApp,
27
+ moduleId?: string,
28
+ ): Promise<void> {
28
29
  const activeMapName = app.maps.activeMap?.name;
29
- const module = app.getModuleById(moduleId);
30
- if (module) {
31
- await app.removeModule(moduleId);
30
+ if (moduleId) {
31
+ const module = app.getModuleById(moduleId);
32
+ if (module) {
33
+ await app.removeModule(moduleId);
34
+ }
32
35
  }
33
36
  if (!app.maps.activeMap) {
34
37
  await app.maps.setActiveMap(activeMapName || [...app.maps][0]?.name);
@@ -36,31 +39,3 @@ export async function unloadModule(app: VcsUiApp): Promise<void> {
36
39
  }
37
40
 
38
41
  export const windowIdModuleSelector = 'moduleSelector_window_id';
39
-
40
- export async function startApplication(
41
- mainModuleIndex: number | undefined | null,
42
- nestedModuleIndex: number | undefined | null,
43
- app: VcsUiApp,
44
- modules: Module<ModuleType>[],
45
- basisModule?: BasisModule,
46
- ): Promise<void> {
47
- await unloadModule(app);
48
-
49
- if (mainModuleIndex === null && !basisModule) {
50
- app.windowManager.remove(windowIdModuleSelector);
51
- return;
52
- }
53
-
54
- const mainModule = modules[mainModuleIndex!];
55
- const nestedModule =
56
- mainModule?.type === 'group'
57
- ? mainModule.cards?.[nestedModuleIndex!]
58
- : null;
59
-
60
- if (nestedModule?.moduleUrl) {
61
- await loadModule(nestedModule.moduleUrl, app);
62
- } else if (mainModule?.type === 'url') {
63
- await loadModule(mainModule.moduleUrl, app);
64
- }
65
- app.windowManager.remove(windowIdModuleSelector);
66
- }