@autoafleveren/ui 1.8.0 → 1.8.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autoafleveren/ui",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist/*",
@@ -1,18 +1,27 @@
1
- import { createApp, inject, isRef, ref } from 'vue';
2
- import { RouterView } from 'vue-router';
1
+ /* eslint-disable vue/one-component-per-file,@typescript-eslint/explicit-function-return-type */
2
+ import { createApp, defineComponent, h, inject, isRef, ref } from 'vue';
3
+ import { RouterView, useRoute } from 'vue-router';
3
4
  import { AppDrawer } from '~components';
4
5
 
5
6
  import type { App, Component, MaybeRef } from 'vue';
6
7
  import type { ModalInstance, DrawerProps } from '~components/AppDrawer/index.d';
7
8
 
9
+ // eslint-disable-next-line @typescript-eslint/naming-convention
10
+ const KeyedRouterView = defineComponent({
11
+ name: 'KeyedRouterView',
12
+
13
+ setup() {
14
+ const route = useRoute();
15
+
16
+ return () => h(RouterView, { key: route.fullPath });
17
+ },
18
+ });
19
+
8
20
  const state = {
9
21
  instances: ref<ModalInstance[]>([]),
10
22
  };
11
23
 
12
- function closeDrawer(modalInstance: Omit<ModalInstance, 'withRouter' | 'unique'>): void {
13
- modalInstance?.instance?.unmount();
14
- modalInstance?.element?.remove();
15
-
24
+ function removeInstance(modalInstance: Omit<ModalInstance, 'withRouter' | 'unique'>): void {
16
25
  const index = state.instances.value.findIndex(instance => instance.instance._uid === modalInstance.instance._uid);
17
26
 
18
27
  if (index > -1) {
@@ -20,6 +29,13 @@ function closeDrawer(modalInstance: Omit<ModalInstance, 'withRouter' | 'unique'>
20
29
  }
21
30
  }
22
31
 
32
+ function closeDrawer(modalInstance: Omit<ModalInstance, 'withRouter' | 'unique'>): void {
33
+ removeInstance(modalInstance);
34
+
35
+ modalInstance?.instance?.unmount();
36
+ modalInstance?.element?.remove();
37
+ }
38
+
23
39
  export function useDrawer(component?: MaybeRef<Component | string>, options?: DrawerProps) {
24
40
  const instance = ref<ModalInstance>();
25
41
 
@@ -44,7 +60,7 @@ export function useDrawer(component?: MaybeRef<Component | string>, options?: Dr
44
60
  }
45
61
 
46
62
  if (!options?.content && !openOptions.content && openOptions.router) {
47
- openOptions.content = RouterView;
63
+ openOptions.content = KeyedRouterView;
48
64
  }
49
65
 
50
66
  window.scrollTo(0, 0);
@@ -92,7 +108,7 @@ export function useDrawer(component?: MaybeRef<Component | string>, options?: Dr
92
108
  mountDrawer(modalInstance, modalRootElement, !!openOptions.router);
93
109
 
94
110
  if (openOptions.router && !openOptions.unique) {
95
- modalInstance?.config?.globalProperties?.$router?.push?.(openOptions.router);
111
+ modalInstance?.config?.globalProperties?.$router?.replace?.(openOptions.router);
96
112
  }
97
113
 
98
114
  return;
@@ -102,18 +118,23 @@ export function useDrawer(component?: MaybeRef<Component | string>, options?: Dr
102
118
  mountDrawer(modalInstance, modalRootElement, !!openOptions.router);
103
119
 
104
120
  if (openOptions.router) {
105
- modalInstance?.config?.globalProperties?.$router?.push?.(openOptions.router);
121
+ modalInstance?.config?.globalProperties?.$router?.replace?.(openOptions.router);
106
122
  }
107
123
  });
108
124
  }
109
125
  }).finally(() => {
110
126
  if (modalInstance) {
127
+ // Immediately remove from state so subsequent open() calls
128
+ // don't try to reuse this closing instance
129
+ removeInstance({
130
+ ref: modalRef,
131
+ instance: modalInstance,
132
+ element: modalRootElement,
133
+ });
134
+
111
135
  setTimeout(() => {
112
- closeDrawer({
113
- ref: modalRef,
114
- instance: modalInstance,
115
- element: modalRootElement,
116
- });
136
+ modalInstance?.unmount();
137
+ modalRootElement?.remove();
117
138
  }, 500);
118
139
  }
119
140
  });