@data-fair/lib-vue 1.0.0 → 1.1.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/auto-imports.js +13 -0
- package/locale-dayjs-global.d.ts +1 -1
- package/locale-dayjs-global.js +1 -0
- package/locale-dayjs.d.ts +4 -4
- package/locale-dayjs.js +4 -4
- package/package.json +3 -2
- package/reactive-search-params.d.ts +1 -1
- package/reactive-search-params.js +1 -1
- package/session.d.ts +17 -4
- package/session.js +1 -1
- package/ui-notif-global.d.ts +3 -2
- package/ui-notif-global.js +1 -0
- package/ui-notif.d.ts +7 -5
- package/ui-notif.js +46 -17
- package/vite.d.ts +7 -0
- package/vite.js +13 -0
- package/locale-dayjs-types.d.ts +0 -1
package/auto-imports.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// made for https://github.com/unplugin/unplugin-auto-import
|
|
2
|
+
export default [
|
|
3
|
+
'vue',
|
|
4
|
+
'vue-i18n',
|
|
5
|
+
'vue-router',
|
|
6
|
+
{
|
|
7
|
+
'@data-fair/lib-vue/session.js': ['useSession'],
|
|
8
|
+
'@data-fair/lib-vue/reactive-search-params.js': ['useReactiveSearchParams'],
|
|
9
|
+
'@data-fair/lib-vue/locale-dayjs.js': ['useLocaleDayjs'],
|
|
10
|
+
'@data-fair/lib-vue/concept-filters.js': ['useConceptFilters'],
|
|
11
|
+
'@data-fair/lib-vue/ui-notif.js': ['useUiNotif']
|
|
12
|
+
}
|
|
13
|
+
]
|
package/locale-dayjs-global.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const locale:
|
|
1
|
+
export declare const locale: string, dayjs: (date?: string | number | import("dayjs").Dayjs | Date | null | undefined) => import("dayjs").Dayjs & {
|
|
2
2
|
fromNow(withoutSuffix?: boolean): string;
|
|
3
3
|
from(compared: import("dayjs").ConfigType, withoutSuffix?: boolean): string;
|
|
4
4
|
toNow(withoutSuffix?: boolean): string;
|
package/locale-dayjs-global.js
CHANGED
|
@@ -4,4 +4,5 @@ import { getLocaleDayjs } from './locale-dayjs.js'
|
|
|
4
4
|
if (import.meta.env?.SSR) {
|
|
5
5
|
throw new Error('this module uses a module level singleton, it cannot be used in SSR mode')
|
|
6
6
|
}
|
|
7
|
+
console.error('locale-dayjs-global is deprecated, please use create + use')
|
|
7
8
|
export const { locale, dayjs } = getLocaleDayjs()
|
package/locale-dayjs.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Dayjs, ConfigType } from 'dayjs';
|
|
2
|
-
import type {
|
|
2
|
+
import type { App } from 'vue';
|
|
3
3
|
import dayjs from 'dayjs';
|
|
4
4
|
import 'dayjs/locale/fr';
|
|
5
5
|
import 'dayjs/locale/en';
|
|
@@ -9,12 +9,12 @@ type RelativeDayjs = Dayjs & {
|
|
|
9
9
|
toNow(withoutSuffix?: boolean): string;
|
|
10
10
|
to(compared: ConfigType, withoutSuffix?: boolean): string;
|
|
11
11
|
};
|
|
12
|
-
export declare function getLocaleDayjs(
|
|
13
|
-
locale:
|
|
12
|
+
export declare function getLocaleDayjs(locale?: string): {
|
|
13
|
+
locale: string;
|
|
14
14
|
dayjs: (date?: string | number | dayjs.Dayjs | Date | null | undefined) => RelativeDayjs;
|
|
15
15
|
};
|
|
16
16
|
export declare const localeDayjsKey: unique symbol;
|
|
17
|
-
export declare function createLocaleDayjs(locale
|
|
17
|
+
export declare function createLocaleDayjs(locale?: string): {
|
|
18
18
|
install(app: App): void;
|
|
19
19
|
};
|
|
20
20
|
export declare function useLocaleDayjs(): ReturnType<typeof getLocaleDayjs>;
|
package/locale-dayjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { inject
|
|
1
|
+
import { inject } from 'vue'
|
|
2
2
|
import dayjs from 'dayjs'
|
|
3
3
|
import 'dayjs/locale/fr'
|
|
4
4
|
import 'dayjs/locale/en'
|
|
@@ -8,12 +8,12 @@ dayjs.extend(localizedFormat)
|
|
|
8
8
|
dayjs.extend(relativeTime)
|
|
9
9
|
// main functionality, use through the createLocaleDayjs plugin and useLocaleDayjs composable
|
|
10
10
|
// or as a global singleton through ./locale-dayjs-global.js
|
|
11
|
-
export function getLocaleDayjs (
|
|
12
|
-
|
|
11
|
+
export function getLocaleDayjs (locale) {
|
|
12
|
+
locale = locale ?? 'fr'
|
|
13
13
|
return {
|
|
14
14
|
locale,
|
|
15
15
|
dayjs: (date) => {
|
|
16
|
-
return dayjs(date).locale(locale
|
|
16
|
+
return dayjs(date).locale(locale)
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@data-fair/lib-vue",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Composables and other utilities for Vue applications in the data-fair stack.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"author": "",
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"scripts": {
|
|
13
|
-
"prepublishOnly": "cd .. && npm run prepublishOnly"
|
|
13
|
+
"prepublishOnly": "cd .. && npm run prepublishOnly",
|
|
14
|
+
"build": "cd .. && npm run build"
|
|
14
15
|
},
|
|
15
16
|
"peerDependencies": {
|
|
16
17
|
"dayjs": "1",
|
|
@@ -4,7 +4,7 @@ export declare function getReactiveSearchParams(router?: Router): Record<string,
|
|
|
4
4
|
export declare const reactiveSearchParamsKey: unique symbol;
|
|
5
5
|
export declare function createReactiveSearchParams(router?: Router): {
|
|
6
6
|
install(app: App): void;
|
|
7
|
-
|
|
7
|
+
state: Record<string, string>;
|
|
8
8
|
};
|
|
9
9
|
export declare function useReactiveSearchParams(): ReturnType<typeof getReactiveSearchParams>;
|
|
10
10
|
export declare const useStringSearchParam: (key: string, options?: string | {
|
|
@@ -82,7 +82,7 @@ export function createReactiveSearchParams (router) {
|
|
|
82
82
|
const reactiveSearchParams = getReactiveSearchParams(router)
|
|
83
83
|
return {
|
|
84
84
|
install (app) { app.provide(reactiveSearchParamsKey, reactiveSearchParams) },
|
|
85
|
-
|
|
85
|
+
state: reactiveSearchParams
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
export function useReactiveSearchParams () {
|
package/session.d.ts
CHANGED
|
@@ -3,15 +3,16 @@ import { type Ref, App } from 'vue';
|
|
|
3
3
|
import { type RouteLocation } from 'vue-router';
|
|
4
4
|
import { type fetch } from 'ofetch';
|
|
5
5
|
import { type SessionState, type SessionStateAuthenticated } from '@data-fair/lib-common-types/session/index.js';
|
|
6
|
+
export type { SessionState, SessionStateAuthenticated, User, Account } from '@data-fair/lib-common-types/session/index.js';
|
|
6
7
|
interface GenericCookies {
|
|
7
8
|
get: (key: string) => string | undefined;
|
|
8
9
|
set: (key: string, value: string, options?: Record<string, any>) => void;
|
|
9
10
|
remove: (key: string) => void;
|
|
10
11
|
}
|
|
11
12
|
export interface SessionOptions {
|
|
13
|
+
sitePath: string;
|
|
14
|
+
directoryUrl: string;
|
|
12
15
|
route?: RouteLocation;
|
|
13
|
-
sitePath?: string;
|
|
14
|
-
directoryUrl?: string;
|
|
15
16
|
logoutRedirectUrl?: string;
|
|
16
17
|
req?: IncomingMessage;
|
|
17
18
|
cookies?: GenericCookies;
|
|
@@ -35,11 +36,23 @@ export interface Session {
|
|
|
35
36
|
export type SessionAuthenticated = Session & {
|
|
36
37
|
state: SessionStateAuthenticated;
|
|
37
38
|
};
|
|
38
|
-
export declare function getSession(initOptions: SessionOptions): Promise<Session>;
|
|
39
|
+
export declare function getSession(initOptions: Partial<SessionOptions>): Promise<Session>;
|
|
39
40
|
export declare const sessionKey: unique symbol;
|
|
40
41
|
export declare function createSession(initOptions: SessionOptions): Promise<{
|
|
41
42
|
install(app: App): void;
|
|
42
|
-
|
|
43
|
+
state: SessionState;
|
|
44
|
+
loginUrl: (redirect?: string, extraParams?: Record<string, string>, immediateRedirect?: true) => string;
|
|
45
|
+
login: (redirect?: string, extraParams?: Record<string, string>, immediateRedirect?: true) => void;
|
|
46
|
+
logout: (redirect?: string) => Promise<void>;
|
|
47
|
+
switchOrganization: (org: string | null, dep?: string) => void;
|
|
48
|
+
setAdminMode: (adminMode: boolean, redirect?: string) => Promise<void>;
|
|
49
|
+
asAdmin: (user: any | null) => Promise<void>;
|
|
50
|
+
cancelDeletion: () => Promise<void>;
|
|
51
|
+
keepalive: () => Promise<void>;
|
|
52
|
+
switchDark: (value: boolean) => void;
|
|
53
|
+
switchLang: (value: string) => void;
|
|
54
|
+
topLocation: Ref<Location | undefined>;
|
|
55
|
+
options: SessionOptions;
|
|
43
56
|
}>;
|
|
44
57
|
export declare function useSession(): Session;
|
|
45
58
|
export declare function useSessionAuthenticated(errorBuilder?: () => any): SessionAuthenticated;
|
package/session.js
CHANGED
|
@@ -238,8 +238,8 @@ export const sessionKey = Symbol('session')
|
|
|
238
238
|
export async function createSession (initOptions) {
|
|
239
239
|
const session = await getSession(initOptions)
|
|
240
240
|
return {
|
|
241
|
+
...session,
|
|
241
242
|
install (app) { app.provide(sessionKey, session) },
|
|
242
|
-
value: session
|
|
243
243
|
}
|
|
244
244
|
}
|
|
245
245
|
export function useSession () {
|
package/ui-notif-global.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
-
|
|
2
|
+
notification: import("vue").Ref<{
|
|
3
3
|
type?: ("default" | "info" | "success" | "warning") | undefined;
|
|
4
4
|
msg: string;
|
|
5
5
|
} | {
|
|
@@ -16,6 +16,7 @@ declare const _default: {
|
|
|
16
16
|
error: any;
|
|
17
17
|
errorMsg: string;
|
|
18
18
|
} | null>;
|
|
19
|
-
|
|
19
|
+
sendUiNotif: (partialNotif: import("./ui-notif.js").PartialUiNotif) => void;
|
|
20
|
+
withUiNotif: <F extends (...args: any[]) => Promise<any>>(fn: F, errorMsg: string, successNotif?: import("./ui-notif.js").PartialUiNotif) => F;
|
|
20
21
|
};
|
|
21
22
|
export default _default;
|
package/ui-notif-global.js
CHANGED
|
@@ -4,4 +4,5 @@ import { getUiNotif } from './ui-notif.js'
|
|
|
4
4
|
if (import.meta.env?.SSR) {
|
|
5
5
|
throw new Error('this module uses a module level singleton, it cannot be used in SSR mode')
|
|
6
6
|
}
|
|
7
|
+
console.error('ui-notif-global is deprecated, please use create + use')
|
|
7
8
|
export default getUiNotif()
|
package/ui-notif.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { App } from 'vue';
|
|
2
2
|
export type UiNotif = UiNotifBase | UiNotifError;
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
type NotifType = 'default' | 'info' | 'success' | 'warning' | 'error';
|
|
4
|
+
export type PartialUiNotif = string | {
|
|
5
|
+
type?: NotifType;
|
|
5
6
|
msg: string;
|
|
6
7
|
error?: any;
|
|
7
8
|
errorMsg?: string;
|
|
8
|
-
}
|
|
9
|
+
};
|
|
9
10
|
interface UiNotifBase {
|
|
10
11
|
type?: 'default' | 'info' | 'success' | 'warning';
|
|
11
12
|
msg: string;
|
|
@@ -17,7 +18,7 @@ interface UiNotifError {
|
|
|
17
18
|
errorMsg: string;
|
|
18
19
|
}
|
|
19
20
|
export declare const getUiNotif: () => {
|
|
20
|
-
|
|
21
|
+
notification: import("vue").Ref<{
|
|
21
22
|
type?: ("default" | "info" | "success" | "warning") | undefined;
|
|
22
23
|
msg: string;
|
|
23
24
|
} | {
|
|
@@ -34,7 +35,8 @@ export declare const getUiNotif: () => {
|
|
|
34
35
|
error: any;
|
|
35
36
|
errorMsg: string;
|
|
36
37
|
} | null>;
|
|
37
|
-
|
|
38
|
+
sendUiNotif: (partialNotif: PartialUiNotif) => void;
|
|
39
|
+
withUiNotif: <F extends (...args: any[]) => Promise<any>>(fn: F, errorMsg: string, successNotif?: PartialUiNotif) => F;
|
|
38
40
|
};
|
|
39
41
|
export declare const uiNotifKey: unique symbol;
|
|
40
42
|
export declare function createUiNotif(): {
|
package/ui-notif.js
CHANGED
|
@@ -1,25 +1,54 @@
|
|
|
1
|
+
// simple composable to display store a UI notification
|
|
2
|
+
// this will be transmitted to frame parent if available (compatible with v-iframe uiNotification message type)
|
|
3
|
+
// or can be displayed locally by @data-fair/lib-vuetify/ui-notif.vue
|
|
1
4
|
import { ref, inject } from 'vue'
|
|
2
5
|
import inIframe from '@data-fair/lib-utils/in-iframe.js'
|
|
3
|
-
function
|
|
4
|
-
if (typeof
|
|
6
|
+
function getErrorMsg (error) {
|
|
7
|
+
if (typeof error === 'string') { return error }
|
|
8
|
+
if (typeof error.data === 'string') { return error.data }
|
|
9
|
+
if (typeof error.response?.data === 'string') { return error.response.data }
|
|
10
|
+
if (typeof error.statusText === 'string') { return error.statusText }
|
|
11
|
+
if (typeof error.response?.statusText === 'string') { return error.response?.statusText }
|
|
12
|
+
if (error.message) { return error.message }
|
|
13
|
+
return 'unknown error'
|
|
14
|
+
}
|
|
15
|
+
function getFullNotif (notif, defaultType = 'default') {
|
|
16
|
+
if (typeof notif === 'string') { return { msg: notif, type: defaultType } }
|
|
5
17
|
if (notif.error) {
|
|
6
|
-
notif.
|
|
7
|
-
|
|
18
|
+
console.log('ERROR', notif.error)
|
|
19
|
+
return {
|
|
20
|
+
...notif,
|
|
21
|
+
type: 'error',
|
|
22
|
+
errorMsg: getErrorMsg(notif.error)
|
|
23
|
+
}
|
|
8
24
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} else {
|
|
13
|
-
console.log('notification', notif)
|
|
25
|
+
return {
|
|
26
|
+
...notif,
|
|
27
|
+
type: notif.type ?? defaultType
|
|
14
28
|
}
|
|
15
|
-
throw new Error('invalid UI notification')
|
|
16
29
|
}
|
|
17
30
|
export const getUiNotif = () => {
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
|
|
31
|
+
const notification = ref(null)
|
|
32
|
+
const sendUiNotif = (partialNotif) => {
|
|
33
|
+
const notif = notification.value = getFullNotif(partialNotif)
|
|
34
|
+
if (inIframe) {
|
|
35
|
+
window.top?.postMessage({ vIframe: true, uiNotification: notif }, '*')
|
|
36
|
+
} else {
|
|
37
|
+
console.log('iframe notification', notif)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function withUiNotif (fn, errorMsg, successNotif) {
|
|
41
|
+
return async function (...args) {
|
|
42
|
+
try {
|
|
43
|
+
const result = await fn(...args)
|
|
44
|
+
if (successNotif) { sendUiNotif(getFullNotif(successNotif, 'success')) }
|
|
45
|
+
return result
|
|
46
|
+
} catch (error) {
|
|
47
|
+
sendUiNotif({ msg: errorMsg, error })
|
|
48
|
+
}
|
|
49
|
+
}
|
|
21
50
|
}
|
|
22
|
-
return {
|
|
51
|
+
return { notification, sendUiNotif, withUiNotif }
|
|
23
52
|
}
|
|
24
53
|
// uses pattern for SSR friendly plugin/composable, cf https://antfu.me/posts/composable-vue-vueday-2021#shared-state-ssr-friendly
|
|
25
54
|
export const uiNotifKey = Symbol('uiNotif')
|
|
@@ -28,8 +57,8 @@ export function createUiNotif () {
|
|
|
28
57
|
return { install (app) { app.provide(uiNotifKey, uiNotif) } }
|
|
29
58
|
}
|
|
30
59
|
export function useUiNotif () {
|
|
31
|
-
const
|
|
32
|
-
if (!
|
|
33
|
-
return
|
|
60
|
+
const uiNotif = inject(uiNotifKey)
|
|
61
|
+
if (!uiNotif) { throw new Error('useUiNotif requires using the plugin createUiNotif') }
|
|
62
|
+
return uiNotif
|
|
34
63
|
}
|
|
35
64
|
export default useUiNotif
|
package/vite.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const autoImports: (string | {
|
|
2
|
+
'@data-fair/lib-vue/session.js': string[];
|
|
3
|
+
'@data-fair/lib-vue/reactive-search-params.js': string[];
|
|
4
|
+
'@data-fair/lib-vue/locale-dayjs.js': string[];
|
|
5
|
+
'@data-fair/lib-vue/concept-filters.js': string[];
|
|
6
|
+
'@data-fair/lib-vue/ui-notif.js': string[];
|
|
7
|
+
})[];
|
package/vite.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// made for https://github.com/unplugin/unplugin-auto-import
|
|
2
|
+
export const autoImports = [
|
|
3
|
+
'vue',
|
|
4
|
+
'vue-i18n',
|
|
5
|
+
'vue-router',
|
|
6
|
+
{
|
|
7
|
+
'@data-fair/lib-vue/session.js': ['useSession'],
|
|
8
|
+
'@data-fair/lib-vue/reactive-search-params.js': ['useReactiveSearchParams'],
|
|
9
|
+
'@data-fair/lib-vue/locale-dayjs.js': ['useLocaleDayjs'],
|
|
10
|
+
'@data-fair/lib-vue/concept-filters.js': ['useConceptFilters'],
|
|
11
|
+
'@data-fair/lib-vue/ui-notif.js': ['useUiNotif']
|
|
12
|
+
}
|
|
13
|
+
]
|
package/locale-dayjs-types.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|