@data-fair/lib-vue 1.25.5 → 1.27.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/fetch.d.ts +1 -0
- package/fetch.js +3 -0
- package/leave-guard.d.ts +7 -0
- package/leave-guard.js +26 -0
- package/package.json +1 -1
- package/vite.d.ts +1 -0
- package/vite.js +1 -0
package/fetch.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export type UseFetchOptions = {
|
|
|
6
6
|
watch?: Boolean;
|
|
7
7
|
notifError?: Boolean;
|
|
8
8
|
immediate?: Boolean;
|
|
9
|
+
waitFor?: MaybeRefOrGetter<Boolean>;
|
|
9
10
|
};
|
|
10
11
|
type OptionalUrl = string | null | undefined;
|
|
11
12
|
export declare function useFetch<T>(url: MaybeRefOrGetter<OptionalUrl>, options?: UseFetchOptions): {
|
package/fetch.js
CHANGED
|
@@ -8,6 +8,9 @@ export function useFetch(url, options = {}) {
|
|
|
8
8
|
url = computed(url);
|
|
9
9
|
const fullUrl = computed(() => {
|
|
10
10
|
let fullUrl = toValue(url);
|
|
11
|
+
const waitFor = toValue(options.waitFor);
|
|
12
|
+
if (waitFor === false)
|
|
13
|
+
return null;
|
|
11
14
|
if (!fullUrl)
|
|
12
15
|
return null;
|
|
13
16
|
const query = toValue(options.query);
|
package/leave-guard.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MaybeRefOrGetter } from 'vue';
|
|
2
|
+
type LeaveGuardOptions = {
|
|
3
|
+
locale?: MaybeRefOrGetter<string>;
|
|
4
|
+
message?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const useLeaveGuard: (isDirty: MaybeRefOrGetter<boolean>, options?: LeaveGuardOptions) => void;
|
|
7
|
+
export default useLeaveGuard;
|
package/leave-guard.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// maybe this will be a part of vueuse someday https://github.com/vueuse/vueuse/issues/4350
|
|
2
|
+
import { onBeforeRouteLeave } from 'vue-router';
|
|
3
|
+
import { toValue, onMounted, onUnmounted } from 'vue';
|
|
4
|
+
const messages = {
|
|
5
|
+
fr: 'Attention ! La page contient des modifications non enregistrées.',
|
|
6
|
+
en: 'Warning ! The page contains unsaved modifications.'
|
|
7
|
+
};
|
|
8
|
+
export const useLeaveGuard = (isDirty, options) => {
|
|
9
|
+
const getMessage = () => options?.message ?? messages[options?.locale ? toValue(options.locale) : 'en'] ?? messages.en;
|
|
10
|
+
// vue router guard
|
|
11
|
+
onBeforeRouteLeave(() => {
|
|
12
|
+
if (!toValue(isDirty))
|
|
13
|
+
return;
|
|
14
|
+
return window.confirm(getMessage());
|
|
15
|
+
});
|
|
16
|
+
// browser guard
|
|
17
|
+
const handleWindowClose = (e) => {
|
|
18
|
+
if (!toValue(isDirty))
|
|
19
|
+
return;
|
|
20
|
+
e.preventDefault();
|
|
21
|
+
e.returnValue = getMessage();
|
|
22
|
+
};
|
|
23
|
+
onMounted(() => window.addEventListener('beforeunload', handleWindowClose));
|
|
24
|
+
onUnmounted(() => window.removeEventListener('beforeunload', handleWindowClose));
|
|
25
|
+
};
|
|
26
|
+
export default useLeaveGuard;
|
package/package.json
CHANGED
package/vite.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export declare const autoImports: (string | {
|
|
|
8
8
|
'@data-fair/lib-vue/edit-fetch.js': string[];
|
|
9
9
|
'@data-fair/lib-vue/ws.js': string[];
|
|
10
10
|
'@data-fair/lib-vue/async-action.js': string[];
|
|
11
|
+
'@data-fair/lib-vue/leave-guard.js': string[];
|
|
11
12
|
'@data-fair/lib-vue/deep-diff.js': string[];
|
|
12
13
|
'@data-fair/lib-vue/format/bytes.js': string[];
|
|
13
14
|
})[];
|
package/vite.js
CHANGED
|
@@ -13,6 +13,7 @@ export const autoImports = [
|
|
|
13
13
|
'@data-fair/lib-vue/edit-fetch.js': ['useEditFetch'],
|
|
14
14
|
'@data-fair/lib-vue/ws.js': ['useWS'],
|
|
15
15
|
'@data-fair/lib-vue/async-action.js': ['useAsyncAction'],
|
|
16
|
+
'@data-fair/lib-vue/leave-guard.js': ['useLeaveGuard'],
|
|
16
17
|
'@data-fair/lib-vue/deep-diff.js': ['computedDeepDiff', 'watchDeepDiff'],
|
|
17
18
|
'@data-fair/lib-vue/format/bytes.js': ['formatBytes'],
|
|
18
19
|
}
|