@data-fair/lib-vue 1.29.1 → 1.30.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.
- package/leave-guard.d.ts +1 -0
- package/leave-guard.js +4 -1
- package/leave-guard.js.map +1 -1
- package/package.json +1 -1
package/leave-guard.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { MaybeRefOrGetter } from 'vue';
|
|
|
2
2
|
type LeaveGuardOptions = {
|
|
3
3
|
locale?: MaybeRefOrGetter<string>;
|
|
4
4
|
message?: string;
|
|
5
|
+
onConfirmLeave?: () => void;
|
|
5
6
|
};
|
|
6
7
|
export declare const useLeaveGuard: (isDirty: MaybeRefOrGetter<boolean>, options?: LeaveGuardOptions) => void;
|
|
7
8
|
export default useLeaveGuard;
|
package/leave-guard.js
CHANGED
|
@@ -11,7 +11,10 @@ export const useLeaveGuard = (isDirty, options) => {
|
|
|
11
11
|
onBeforeRouteLeave(() => {
|
|
12
12
|
if (!toValue(isDirty))
|
|
13
13
|
return;
|
|
14
|
-
|
|
14
|
+
const leave = window.confirm(getMessage());
|
|
15
|
+
if (leave)
|
|
16
|
+
options?.onConfirmLeave?.();
|
|
17
|
+
return leave;
|
|
15
18
|
});
|
|
16
19
|
// browser guard
|
|
17
20
|
const handleWindowClose = (e) => {
|
package/leave-guard.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"leave-guard.js","sourceRoot":"","sources":["leave-guard.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAG3F,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,KAAK,CAAA;AAErD,MAAM,QAAQ,GAA2B;IACvC,EAAE,EAAE,kEAAkE;IACtE,EAAE,EAAE,oDAAoD;CACzD,CAAA;
|
|
1
|
+
{"version":3,"file":"leave-guard.js","sourceRoot":"","sources":["leave-guard.ts"],"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AAC,CAAA;AAClF,CAAC,CAAA;AAED,eAAe,aAAa,CAAA","sourcesContent":["// maybe this will be a part of vueuse someday https://github.com/vueuse/vueuse/issues/4350\n\nimport type { MaybeRefOrGetter } from 'vue'\nimport { onBeforeRouteLeave } from 'vue-router'\nimport { toValue, onMounted, onUnmounted } from 'vue'\n\nconst messages: Record<string, string> = {\n fr: 'Attention ! La page contient des modifications non enregistrées.',\n en: 'Warning ! The page contains unsaved modifications.'\n}\n\ntype LeaveGuardOptions = {\n locale?: MaybeRefOrGetter<string>,\n message?: string,\n onConfirmLeave?: () => void\n}\n\nexport const useLeaveGuard = (isDirty: MaybeRefOrGetter<boolean>, options?: LeaveGuardOptions) => {\n const getMessage = () => options?.message ?? messages[options?.locale ? toValue(options.locale) : 'en'] ?? messages.en\n\n // vue router guard\n onBeforeRouteLeave(() => {\n if (!toValue(isDirty)) return\n const leave = window.confirm(getMessage())\n if (leave) options?.onConfirmLeave?.()\n return leave\n })\n\n // browser guard\n const handleWindowClose = (e: BeforeUnloadEvent) => {\n if (!toValue(isDirty)) return\n e.preventDefault()\n e.returnValue = getMessage()\n }\n onMounted(() => window.addEventListener('beforeunload', handleWindowClose))\n onUnmounted(() => window.removeEventListener('beforeunload', handleWindowClose))\n}\n\nexport default useLeaveGuard\n"]}
|