@dev.smartpricing/message-composer-layer 1.0.22 → 1.0.23
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,62 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useEventListener } from '@vueuse/core'
|
|
3
|
-
import { type RouteLocationRaw } from 'vue-router'
|
|
1
|
+
import { type ComputedRef } from 'vue'
|
|
4
2
|
|
|
5
3
|
export function useExitConfirmation(shouldBlockNavigation: ComputedRef<boolean>) {
|
|
6
|
-
const isForcingNavigation = ref(false)
|
|
7
|
-
const isNavigatingTo = ref<RouteLocationRaw | null>(null)
|
|
8
|
-
const isPopstateNavigation = ref(false)
|
|
9
|
-
const isSelfTriggeredBack = ref(false)
|
|
10
|
-
|
|
11
4
|
const { confirm } = useConfirm()
|
|
12
5
|
const { t } = useI18n()
|
|
13
|
-
const { goBackOrFallback } = useGoBack()
|
|
14
|
-
|
|
15
|
-
// Detect browser back/forward navigation
|
|
16
|
-
useEventListener(window, 'popstate', () => {
|
|
17
|
-
if (isSelfTriggeredBack.value) {
|
|
18
|
-
isSelfTriggeredBack.value = false
|
|
19
|
-
return
|
|
20
|
-
}
|
|
21
|
-
isPopstateNavigation.value = true
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
// Setup route guard
|
|
25
|
-
onBeforeRouteLeave((_to, _from, next) => {
|
|
26
|
-
const _isForcedNavigation = unref(isForcingNavigation)
|
|
27
|
-
isForcingNavigation.value = false
|
|
28
6
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
isPopstateNavigation.value = false
|
|
7
|
+
onBeforeRouteLeave(async () => {
|
|
8
|
+
if (!shouldBlockNavigation.value) return
|
|
32
9
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
10
|
+
const confirmed = await confirm({
|
|
11
|
+
title: t('dialogs.unsaved_changes.title'),
|
|
12
|
+
message: t('dialogs.unsaved_changes.message'),
|
|
13
|
+
confirmProps: { label: t('dialogs.unsaved_changes.leave') },
|
|
14
|
+
cancelProps: { label: t('dialogs.unsaved_changes.cancel') },
|
|
15
|
+
})
|
|
36
16
|
|
|
37
|
-
|
|
38
|
-
title: t('dialogs.unsaved_changes.title'),
|
|
39
|
-
message: t('dialogs.unsaved_changes.message'),
|
|
40
|
-
confirmProps: { label: t('dialogs.unsaved_changes.leave') },
|
|
41
|
-
cancelProps: { label: t('dialogs.unsaved_changes.cancel') },
|
|
42
|
-
action: () => {
|
|
43
|
-
const target = isNavigatingTo.value
|
|
44
|
-
if (target) {
|
|
45
|
-
isForcingNavigation.value = true
|
|
46
|
-
if (wasPopstate) {
|
|
47
|
-
isSelfTriggeredBack.value = true
|
|
48
|
-
goBackOrFallback(target)
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
navigateTo(target)
|
|
52
|
-
}
|
|
53
|
-
isNavigatingTo.value = null
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
})
|
|
57
|
-
} else {
|
|
58
|
-
isNavigatingTo.value = null
|
|
59
|
-
next()
|
|
60
|
-
}
|
|
17
|
+
if (!confirmed) return false
|
|
61
18
|
})
|
|
62
19
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dev.smartpricing/message-composer-layer",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.23",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./nuxt.config.ts",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"vue-router": "^5.0.6",
|
|
40
40
|
"vue3-emoji-picker": "^1.1.8",
|
|
41
41
|
"zod": "^4.4.1",
|
|
42
|
-
"@dev.smartpricing/message-composer-utils": "3.1.
|
|
42
|
+
"@dev.smartpricing/message-composer-utils": "3.1.23"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@nuxt/eslint": "^1.15.2",
|