@data-fair/lib-vue 1.9.3 → 1.10.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/locale-dayjs-global.d.ts +2 -0
- package/locale-dayjs.d.ts +6 -2
- package/locale-dayjs.js +5 -0
- package/package.json +1 -1
- package/session.js +1 -21
- package/auto-imports.js +0 -13
- package/locale-dayjs-types.js +0 -1
- package/ui-notif-global.js +0 -8
package/locale-dayjs-global.d.ts
CHANGED
|
@@ -3,4 +3,6 @@ export declare const locale: string, dayjs: (date?: string | number | import("da
|
|
|
3
3
|
from(compared: import("dayjs").ConfigType, withoutSuffix?: boolean): string;
|
|
4
4
|
toNow(withoutSuffix?: boolean): string;
|
|
5
5
|
to(compared: import("dayjs").ConfigType, withoutSuffix?: boolean): string;
|
|
6
|
+
add(duration: import("dayjs/plugin/duration.js").Duration): import("dayjs").Dayjs & any;
|
|
7
|
+
subtract(duration: import("dayjs/plugin/duration.js").Duration): import("dayjs").Dayjs & any;
|
|
6
8
|
};
|
package/locale-dayjs.d.ts
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import type { Dayjs, ConfigType } from 'dayjs';
|
|
2
1
|
import type { App } from 'vue';
|
|
3
|
-
import dayjs from 'dayjs';
|
|
2
|
+
import dayjs, { type Dayjs, ConfigType } from 'dayjs';
|
|
4
3
|
import 'dayjs/locale/fr';
|
|
5
4
|
import 'dayjs/locale/en';
|
|
5
|
+
import duration, { type Duration } from 'dayjs/plugin/duration.js';
|
|
6
|
+
export type { ConfigType as DayjsConfigType } from 'dayjs';
|
|
6
7
|
type RelativeDayjs = Dayjs & {
|
|
7
8
|
fromNow(withoutSuffix?: boolean): string;
|
|
8
9
|
from(compared: ConfigType, withoutSuffix?: boolean): string;
|
|
9
10
|
toNow(withoutSuffix?: boolean): string;
|
|
10
11
|
to(compared: ConfigType, withoutSuffix?: boolean): string;
|
|
12
|
+
add(duration: Duration): RelativeDayjs;
|
|
13
|
+
subtract(duration: Duration): RelativeDayjs;
|
|
11
14
|
};
|
|
12
15
|
export declare function getLocaleDayjs(locale?: string): {
|
|
13
16
|
locale: string;
|
|
17
|
+
duration: (dur: duration.DurationUnitsObjectType) => duration.Duration;
|
|
14
18
|
dayjs: (date?: string | number | dayjs.Dayjs | Date | null | undefined) => RelativeDayjs;
|
|
15
19
|
};
|
|
16
20
|
export declare const localeDayjsKey: unique symbol;
|
package/locale-dayjs.js
CHANGED
|
@@ -4,14 +4,19 @@ import 'dayjs/locale/fr'
|
|
|
4
4
|
import 'dayjs/locale/en'
|
|
5
5
|
import localizedFormat from 'dayjs/plugin/localizedFormat.js'
|
|
6
6
|
import relativeTime from 'dayjs/plugin/relativeTime.js'
|
|
7
|
+
import duration from 'dayjs/plugin/duration.js'
|
|
7
8
|
dayjs.extend(localizedFormat)
|
|
8
9
|
dayjs.extend(relativeTime)
|
|
10
|
+
dayjs.extend(duration)
|
|
9
11
|
// main functionality, use through the createLocaleDayjs plugin and useLocaleDayjs composable
|
|
10
12
|
// or as a global singleton through ./locale-dayjs-global.js
|
|
11
13
|
export function getLocaleDayjs (locale) {
|
|
12
14
|
locale = locale ?? 'fr'
|
|
13
15
|
return {
|
|
14
16
|
locale,
|
|
17
|
+
duration: (dur) => {
|
|
18
|
+
return dayjs.duration(dur).locale(locale)
|
|
19
|
+
},
|
|
15
20
|
dayjs: (date) => {
|
|
16
21
|
return dayjs(date).locale(locale)
|
|
17
22
|
}
|
package/package.json
CHANGED
package/session.js
CHANGED
|
@@ -37,10 +37,6 @@ const goTo = (url) => {
|
|
|
37
37
|
}
|
|
38
38
|
if (url) { topLocation.href = url } else { topLocation.reload() }
|
|
39
39
|
}
|
|
40
|
-
const getSiteInfoStorage = (sitePath) => {
|
|
41
|
-
const siteInfoStorageStr = window.localStorage.getItem('sd-site-info' + sitePath)
|
|
42
|
-
return siteInfoStorageStr ? JSON.parse(siteInfoStorageStr) : null
|
|
43
|
-
}
|
|
44
40
|
const defaultOptions = { directoryUrl: '/simple-directory', sitePath: '', defaultLang: 'fr' }
|
|
45
41
|
export async function getSession (initOptions) {
|
|
46
42
|
const options = { ...defaultOptions, ...initOptions }
|
|
@@ -113,10 +109,6 @@ export async function getSession (initOptions) {
|
|
|
113
109
|
}
|
|
114
110
|
state.accountRole = 'admin'
|
|
115
111
|
}
|
|
116
|
-
if (!ssr) {
|
|
117
|
-
const siteInfoStorage = getSiteInfoStorage(options.sitePath)
|
|
118
|
-
site.value = siteInfoStorage ? siteInfoStorage.info : null
|
|
119
|
-
}
|
|
120
112
|
}
|
|
121
113
|
readState()
|
|
122
114
|
debug('initial state', state)
|
|
@@ -222,17 +214,11 @@ export async function getSession (initOptions) {
|
|
|
222
214
|
await customFetch(`${options.directoryUrl}/api/auth/keepalive`, { method: 'POST' })
|
|
223
215
|
readState()
|
|
224
216
|
}
|
|
225
|
-
const setSiteInfoStorage = (siteInfo) => {
|
|
226
|
-
const siteInfoStorage = { info: siteInfo, updatedAt: new Date().getTime() }
|
|
227
|
-
window.localStorage.setItem('sd-site-info' + options.sitePath, JSON.stringify(siteInfoStorage))
|
|
228
|
-
}
|
|
229
217
|
const refreshSiteInfo = async () => {
|
|
230
218
|
const siteInfo = await customFetch(`${options.directoryUrl}/api/sites/_public`) ?? null
|
|
231
219
|
site.value = siteInfo
|
|
232
|
-
if (!ssr) {
|
|
233
|
-
setSiteInfoStorage(siteInfo)
|
|
234
|
-
}
|
|
235
220
|
}
|
|
221
|
+
if (options.siteInfo) { await refreshSiteInfo() }
|
|
236
222
|
// immediately performs a keepalive, but only on top windows (not iframes or popups)
|
|
237
223
|
// and only if it was not done very recently (maybe from a refreshed page next to this one)
|
|
238
224
|
// also run an auto-refresh loop
|
|
@@ -241,12 +227,6 @@ export async function getSession (initOptions) {
|
|
|
241
227
|
if (state.user && (!lastKeepalive || (new Date().getTime() - Number(lastKeepalive)) > 10000)) {
|
|
242
228
|
await keepalive()
|
|
243
229
|
}
|
|
244
|
-
if (options.siteInfo) {
|
|
245
|
-
const lastSiteInfoStorage = getSiteInfoStorage(options.sitePath)
|
|
246
|
-
if (!lastSiteInfoStorage || (new Date().getTime() - Number(lastSiteInfoStorage.updatedAt)) > 10000) {
|
|
247
|
-
await refreshSiteInfo()
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
230
|
const refreshLoopDelay = 10 * 60 * 1000 // 10 minutes
|
|
251
231
|
setInterval(() => {
|
|
252
232
|
const lastKeepalive = window.localStorage.getItem('sd-keepalive' + options.sitePath)
|
package/auto-imports.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
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-types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {}
|
package/ui-notif-global.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// same as use-ui-notif.js but in a module level singleton for convenience when not using SSR
|
|
2
|
-
import { getUiNotif } from './ui-notif.js'
|
|
3
|
-
// @ts-ignore
|
|
4
|
-
if (import.meta.env?.SSR) {
|
|
5
|
-
throw new Error('this module uses a module level singleton, it cannot be used in SSR mode')
|
|
6
|
-
}
|
|
7
|
-
console.error('ui-notif-global is deprecated, please use create + use')
|
|
8
|
-
export default getUiNotif()
|