@data-fair/lib-vue 1.15.5 → 1.16.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/async-action.js +3 -3
- package/fetch.d.ts +2 -1
- package/fetch.js +12 -4
- package/package.json +1 -1
- package/session.js +7 -6
- package/ui-notif.d.ts +1 -19
- package/ui-notif.js +2 -2
package/async-action.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// similar to withUiNotif but more powerful
|
|
2
|
-
import { ref } from 'vue'
|
|
2
|
+
import { ref, readonly, shallowReadonly, shallowRef } from 'vue'
|
|
3
3
|
import { useUiNotif, getFullNotif, getErrorMsg } from './ui-notif.js'
|
|
4
4
|
export function useAsyncAction (fn, options) {
|
|
5
5
|
const { sendUiNotif } = useUiNotif()
|
|
6
|
-
const notif =
|
|
6
|
+
const notif = shallowRef()
|
|
7
7
|
const loading = ref(false)
|
|
8
8
|
const error = ref()
|
|
9
9
|
const execute = async function (...args) {
|
|
@@ -31,6 +31,6 @@ export function useAsyncAction (fn, options) {
|
|
|
31
31
|
loading.value = false
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
return { execute, notif, loading, error }
|
|
34
|
+
return { execute, notif: shallowReadonly(notif), loading: readonly(loading), error: readonly(error) }
|
|
35
35
|
}
|
|
36
36
|
export default useAsyncAction
|
package/fetch.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ type UseFetchOptions = {
|
|
|
5
5
|
watch?: Boolean;
|
|
6
6
|
notifError?: Boolean;
|
|
7
7
|
};
|
|
8
|
-
|
|
8
|
+
type OptionalUrl = string | null | undefined;
|
|
9
|
+
export declare function useFetch<T>(url: OptionalUrl | Ref<OptionalUrl> | (() => OptionalUrl), options?: UseFetchOptions): {
|
|
9
10
|
data: Ref<T | null>;
|
|
10
11
|
loading: Ref<boolean>;
|
|
11
12
|
initialized: Ref<boolean>;
|
package/fetch.js
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import { ofetch } from 'ofetch'
|
|
2
2
|
import { withQuery } from 'ufo'
|
|
3
|
-
import { computed, isRef, watch, ref } from 'vue'
|
|
3
|
+
import { computed, isRef, watch, ref, shallowRef, readonly, shallowReadonly } from 'vue'
|
|
4
4
|
import { useUiNotif } from '@data-fair/lib-vue/ui-notif.js'
|
|
5
5
|
export function useFetch (url, options = {}) {
|
|
6
6
|
const { sendUiNotif } = useUiNotif()
|
|
7
7
|
if (typeof url === 'function') { url = computed(url) }
|
|
8
8
|
const fullUrl = computed(() => {
|
|
9
9
|
let fullUrl = isRef(url) ? url.value : url
|
|
10
|
+
if (!fullUrl) { return null }
|
|
10
11
|
const query = isRef(options.query) ? options.query.value : options.query
|
|
11
12
|
if (query) { fullUrl = withQuery(fullUrl, query) }
|
|
12
13
|
return fullUrl
|
|
13
14
|
})
|
|
14
|
-
const data =
|
|
15
|
+
const data = shallowRef(null)
|
|
15
16
|
const loading = ref(false)
|
|
16
17
|
const initialized = ref(false)
|
|
17
|
-
const error =
|
|
18
|
+
const error = shallowRef(null)
|
|
18
19
|
let abortController
|
|
19
20
|
const refresh = async () => {
|
|
21
|
+
if (!fullUrl.value) { return null }
|
|
20
22
|
initialized.value = true
|
|
21
23
|
error.value = null
|
|
22
24
|
if (abortController) { abortController.abort() }
|
|
@@ -38,6 +40,12 @@ export function useFetch (url, options = {}) {
|
|
|
38
40
|
if (options.watch !== false) {
|
|
39
41
|
watch(fullUrl, refresh, { immediate: true })
|
|
40
42
|
}
|
|
41
|
-
return {
|
|
43
|
+
return {
|
|
44
|
+
initialized: readonly(initialized),
|
|
45
|
+
data: shallowReadonly(data),
|
|
46
|
+
loading: readonly(loading),
|
|
47
|
+
error: shallowReadonly(error),
|
|
48
|
+
refresh,
|
|
49
|
+
}
|
|
42
50
|
}
|
|
43
51
|
export default useFetch
|
package/package.json
CHANGED
package/session.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { shallowReadonly } from 'vue'
|
|
1
2
|
import { FetchError } from 'ofetch'
|
|
2
|
-
import { reactive, computed, watch, inject, ref } from 'vue'
|
|
3
|
+
import { reactive, computed, watch, inject, ref, shallowRef, readonly } from 'vue'
|
|
3
4
|
import { ofetch } from 'ofetch'
|
|
4
5
|
import { jwtDecode } from 'jwt-decode'
|
|
5
6
|
import cookiesModule from 'universal-cookie'
|
|
@@ -66,8 +67,8 @@ export async function getSession (initOptions) {
|
|
|
66
67
|
})
|
|
67
68
|
// the core state of the session that is filled by reading cookies
|
|
68
69
|
const state = reactive({})
|
|
69
|
-
const fullSite =
|
|
70
|
-
const site =
|
|
70
|
+
const fullSite = shallowRef(null)
|
|
71
|
+
const site = shallowRef(null)
|
|
71
72
|
const theme = ref(null)
|
|
72
73
|
// cookies are the source of truth and this information is transformed into the state reactive object
|
|
73
74
|
const cookies = initOptions?.cookies ?? new Cookies(options.req?.headers.cookie)
|
|
@@ -283,9 +284,9 @@ export async function getSession (initOptions) {
|
|
|
283
284
|
account: computed(() => state.account),
|
|
284
285
|
accountRole: computed(() => state.accountRole),
|
|
285
286
|
lang: computed(() => state.lang),
|
|
286
|
-
theme,
|
|
287
|
-
site,
|
|
288
|
-
fullSite,
|
|
287
|
+
theme: readonly(theme),
|
|
288
|
+
site: shallowReadonly(site),
|
|
289
|
+
fullSite: shallowReadonly(fullSite),
|
|
289
290
|
loginUrl,
|
|
290
291
|
login,
|
|
291
292
|
logout,
|
package/ui-notif.d.ts
CHANGED
|
@@ -22,25 +22,7 @@ export declare function getErrorCode(error: any): number;
|
|
|
22
22
|
export declare function getErrorMsg(error: any): string;
|
|
23
23
|
export declare function getFullNotif(notif: PartialUiNotif, defaultType?: UiNotifBase['type']): UiNotif;
|
|
24
24
|
export declare const getUiNotif: () => {
|
|
25
|
-
notification: import("vue").
|
|
26
|
-
type?: ("default" | "info" | "success" | "warning") | undefined;
|
|
27
|
-
msg: string;
|
|
28
|
-
} | {
|
|
29
|
-
type: "error";
|
|
30
|
-
msg: string;
|
|
31
|
-
error?: any;
|
|
32
|
-
errorMsg: string;
|
|
33
|
-
clientError?: boolean | undefined;
|
|
34
|
-
} | null, UiNotif | {
|
|
35
|
-
type?: ("default" | "info" | "success" | "warning") | undefined;
|
|
36
|
-
msg: string;
|
|
37
|
-
} | {
|
|
38
|
-
type: "error";
|
|
39
|
-
msg: string;
|
|
40
|
-
error?: any;
|
|
41
|
-
errorMsg: string;
|
|
42
|
-
clientError?: boolean | undefined;
|
|
43
|
-
} | null>;
|
|
25
|
+
notification: import("vue").ShallowRef<UiNotif | null, UiNotif | null>;
|
|
44
26
|
sendUiNotif: (partialNotif: PartialUiNotif) => void;
|
|
45
27
|
};
|
|
46
28
|
export declare const uiNotifKey: unique symbol;
|
package/ui-notif.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// simple composable to display store a UI notification
|
|
2
2
|
// this will be transmitted to frame parent if available (compatible with v-iframe uiNotification message type)
|
|
3
3
|
// or can be displayed locally by @data-fair/lib-vuetify/ui-notif.vue
|
|
4
|
-
import {
|
|
4
|
+
import { shallowRef, inject } from 'vue'
|
|
5
5
|
import inIframe from '@data-fair/lib-utils/in-iframe.js'
|
|
6
6
|
export function getErrorCode (error) {
|
|
7
7
|
if (typeof error === 'string') { return 500 }
|
|
@@ -37,7 +37,7 @@ export function getFullNotif (notif, defaultType = 'default') {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
export const getUiNotif = () => {
|
|
40
|
-
const notification =
|
|
40
|
+
const notification = shallowRef(null)
|
|
41
41
|
function sendUiNotif (partialNotif) {
|
|
42
42
|
const notif = notification.value = getFullNotif(partialNotif)
|
|
43
43
|
if (inIframe) {
|