@data-fair/lib-vue 1.27.2 → 1.28.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 CHANGED
@@ -45,3 +45,4 @@ export function useAsyncAction(fn, options) {
45
45
  return { execute, notif: shallowReadonly(notif), loading: readonly(loading), error: readonly(error) };
46
46
  }
47
47
  export default useAsyncAction;
48
+ //# sourceMappingURL=async-action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-action.js","sourceRoot":"","sources":["async-action.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAE3C,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,eAAe,EAAE,UAAU,EAAY,MAAM,KAAK,CAAA;AAC1E,OAAO,EAAqC,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAWxG,MAAM,UAAU,cAAc,CAA8C,EAAK,EAAE,OAAsC;IACvH,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;QAClC,OAAO,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,CAAA;IAChC,CAAC;IACD,MAAM,EAAE,WAAW,EAAE,GAAG,UAAU,EAAE,CAAA;IACpC,MAAM,KAAK,GAAG,UAAU,EAAW,CAAA;IACnC,MAAM,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,CAAA;IAC1B,MAAM,KAAK,GAAG,GAAG,EAAU,CAAA;IAC3B,MAAM,OAAO,GAAO,KAAK,WAAW,GAAG,IAAW;QAChD,OAAO,CAAC,KAAK,GAAG,IAAI,CAAA;QACpB,KAAK,CAAC,KAAK,GAAG,SAAS,CAAA;QACvB,KAAK,CAAC,KAAK,GAAG,SAAS,CAAA;QACvB,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,CAAA;YAChC,IAAI,OAAO,EAAE,OAAO,EAAE,CAAC;gBACrB,MAAM,YAAY,GAAG,YAAY,CAAC,OA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KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAA;AACvG,CAAC;AAED,eAAe,cAAc,CAAA","sourcesContent":["// similar to withUiNotif but more powerful\n\nimport { ref, readonly, shallowReadonly, shallowRef, type Ref } from 'vue'\nimport { type PartialUiNotif, type UiNotif, useUiNotif, getFullNotif, getErrorMsg } from './ui-notif.js'\n\ntype Finally = () => Promise<void> | void\n\nexport type AsyncActionOptions = {\n error?: string,\n success?: PartialUiNotif,\n catch?: 'error' | 'success' | 'all',\n finally?: Finally\n}\n\nexport function useAsyncAction<F extends (...args: any[]) => Promise<any>> (fn: F, options?: AsyncActionOptions | Finally): { execute: F, notif: Ref<UiNotif | undefined>, loading: Ref<boolean>, error: Ref<string | undefined> } {\n if (typeof options === 'function') {\n options = { finally: options }\n }\n const { sendUiNotif } = useUiNotif()\n const notif = shallowRef<UiNotif>()\n const loading = ref(false)\n const error = ref<string>()\n const execute = <F> async function (...args: any[]) {\n loading.value = true\n notif.value = undefined\n error.value = undefined\n try {\n const result = await fn(...args)\n if (options?.success) {\n const successNotif = getFullNotif(options?.success, 'success')\n notif.value = successNotif\n if (options?.catch !== 'success' && options?.catch !== 'all') {\n sendUiNotif(successNotif)\n }\n }\n loading.value = false\n if (options?.finally) await options?.finally()\n return result\n } catch (err: any) {\n const abortError = err.name === 'AbortError' || err.cause?.name === 'AbortError'\n if (!abortError) {\n error.value = getErrorMsg(err)\n const errorNotif = getFullNotif({ msg: options?.error ?? '', error: err })\n notif.value = errorNotif\n if (options?.catch !== 'error' && options?.catch !== 'all') {\n sendUiNotif(errorNotif)\n }\n }\n loading.value = false\n if (options?.finally && !abortError) await options?.finally()\n }\n }\n\n return { execute, notif: shallowReadonly(notif), loading: readonly(loading), error: readonly(error) }\n}\n\nexport default useAsyncAction\n"]}
@@ -0,0 +1,21 @@
1
+ import { type MaybeRefOrGetter } from 'vue';
2
+ /**
3
+ * Stick-to-bottom autoscroll for a growing, live region (a run log, a chat
4
+ * transcript, ...): follows new content while the user is at the bottom, any
5
+ * upward scroll or wheel-up stops it, scrolling back to the bottom resumes.
6
+ *
7
+ * `target` is what actually scrolls — pass `window` (or the current document's
8
+ * scroller) for a page that scrolls as a whole, or a getter returning the inner
9
+ * scrollable element when the growing region lives inside an `overflow: auto`
10
+ * container. VueUse's `arrivedState.bottom` carries a built-in 1px tolerance,
11
+ * and appending content fires no scroll event, so following only ever turns off
12
+ * on a real upward scroll — no manual threshold needed.
13
+ *
14
+ * @param target the scroll container: `window`, an element, or a ref/getter to
15
+ * one (tolerates `null`/`undefined` while the element is not yet mounted)
16
+ * @param growthSignal reactive getter for the content length (the growth signal)
17
+ * @param isActive getter telling whether the source is still streaming/growing
18
+ */
19
+ export declare const useAutoScrollBottom: (target: MaybeRefOrGetter<HTMLElement | Window | null | undefined>, growthSignal: () => number, isActive: () => boolean) => {
20
+ following: import("vue").Ref<boolean, boolean>;
21
+ };
@@ -0,0 +1,51 @@
1
+ import { ref, watch, toValue } from 'vue';
2
+ import { useScroll, useEventListener } from '@vueuse/core';
3
+ /**
4
+ * Stick-to-bottom autoscroll for a growing, live region (a run log, a chat
5
+ * transcript, ...): follows new content while the user is at the bottom, any
6
+ * upward scroll or wheel-up stops it, scrolling back to the bottom resumes.
7
+ *
8
+ * `target` is what actually scrolls — pass `window` (or the current document's
9
+ * scroller) for a page that scrolls as a whole, or a getter returning the inner
10
+ * scrollable element when the growing region lives inside an `overflow: auto`
11
+ * container. VueUse's `arrivedState.bottom` carries a built-in 1px tolerance,
12
+ * and appending content fires no scroll event, so following only ever turns off
13
+ * on a real upward scroll — no manual threshold needed.
14
+ *
15
+ * @param target the scroll container: `window`, an element, or a ref/getter to
16
+ * one (tolerates `null`/`undefined` while the element is not yet mounted)
17
+ * @param growthSignal reactive getter for the content length (the growth signal)
18
+ * @param isActive getter telling whether the source is still streaming/growing
19
+ */
20
+ export const useAutoScrollBottom = (target, growthSignal, isActive) => {
21
+ // Start following so a freshly opened, still-growing source pins to its tail
22
+ // even though it usually mounts scrolled to the top.
23
+ const following = ref(true);
24
+ const { arrivedState, directions, y } = useScroll(target, {
25
+ onScroll: () => {
26
+ if (directions.top)
27
+ following.value = false; // scrolled up → stop
28
+ else if (arrivedState.bottom)
29
+ following.value = true; // back at bottom → resume
30
+ }
31
+ });
32
+ // A wheel-up reaches us even when the target can't scroll (short content, or
33
+ // an auto-height embed where a parent scrolls) — the only "stop following"
34
+ // signal available there.
35
+ useEventListener(target, 'wheel', (e) => { if (e.deltaY < 0)
36
+ following.value = false; }, { passive: true });
37
+ const pinToBottom = () => {
38
+ const el = toValue(target);
39
+ if (!el)
40
+ return;
41
+ // For an element, `y` sets its scrollTop; for the window we scroll to the
42
+ // document's full height (window has no scrollHeight of its own).
43
+ y.value = el instanceof Window
44
+ ? (document.scrollingElement ?? document.documentElement).scrollHeight
45
+ : el.scrollHeight;
46
+ };
47
+ watch(growthSignal, () => { if (isActive() && following.value)
48
+ pinToBottom(); }, { flush: 'post' });
49
+ return { following };
50
+ };
51
+ //# sourceMappingURL=auto-scroll-bottom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto-scroll-bottom.js","sourceRoot":"","sources":["auto-scroll-bottom.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAyB,MAAM,KAAK,CAAA;AAChE,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAE1D;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,MAAiE,EACjE,YAA0B,EAC1B,QAAuB,EACvB,EAAE;IACF,6EAA6E;IAC7E,qDAAqD;IACrD,MAAM,SAAS,GAAG,GAAG,CAAC,IAAI,CAAC,CAAA;IAE3B,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC,MAAM,EAAE;QACxD,QAAQ,EAAE,GAAG,EAAE;YACb,IAAI,UAAU,CAAC,GAAG;gBAAE,SAAS,CAAC,KAAK,GAAG,KAAK,CAAA,CAAC,qBAAqB;iBAC5D,IAAI,YAAY,CAAC,MAAM;gBAAE,SAAS,CAAC,KAAK,GAAG,IAAI,CAAA,CAAC,0BAA0B;QACjF,CAAC;KACF,CAAC,CAAA;IAEF,6EAA6E;IAC7E,2EAA2E;IAC3E,0BAA0B;IAC1B,gBAAgB,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAa,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC;QAAE,SAAS,CAAC,KAAK,GAAG,KAAK,CAAA,CAAC,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;IAEtH,MAAM,WAAW,GAAG,GAAG,EAAE;QACvB,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;QAC1B,IAAI,CAAC,EAAE;YAAE,OAAM;QACf,0EAA0E;QAC1E,kEAAkE;QAClE,CAAC,CAAC,KAAK,GAAG,EAAE,YAAY,MAAM;YAC5B,CAAC,CAAC,CAAC,QAAQ,CAAC,gBAAgB,IAAI,QAAQ,CAAC,eAAe,CAAC,CAAC,YAAY;YACtE,CAAC,CAAC,EAAE,CAAC,YAAY,CAAA;IACrB,CAAC,CAAA;IAED,KAAK,CAAC,YAAY,EAAE,GAAG,EAAE,GAAG,IAAI,QAAQ,EAAE,IAAI,SAAS,CAAC,KAAK;QAAE,WAAW,EAAE,CAAA,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAA;IAElG,OAAO,EAAE,SAAS,EAAE,CAAA;AACtB,CAAC,CAAA","sourcesContent":["import { ref, watch, toValue, type MaybeRefOrGetter } from 'vue'\nimport { useScroll, useEventListener } from '@vueuse/core'\n\n/**\n * Stick-to-bottom autoscroll for a growing, live region (a run log, a chat\n * transcript, ...): follows new content while the user is at the bottom, any\n * upward scroll or wheel-up stops it, scrolling back to the bottom resumes.\n *\n * `target` is what actually scrolls — pass `window` (or the current document's\n * scroller) for a page that scrolls as a whole, or a getter returning the inner\n * scrollable element when the growing region lives inside an `overflow: auto`\n * container. VueUse's `arrivedState.bottom` carries a built-in 1px tolerance,\n * and appending content fires no scroll event, so following only ever turns off\n * on a real upward scroll — no manual threshold needed.\n *\n * @param target the scroll container: `window`, an element, or a ref/getter to\n * one (tolerates `null`/`undefined` while the element is not yet mounted)\n * @param growthSignal reactive getter for the content length (the growth signal)\n * @param isActive getter telling whether the source is still streaming/growing\n */\nexport const useAutoScrollBottom = (\n target: MaybeRefOrGetter<HTMLElement | Window | null | undefined>,\n growthSignal: () => number,\n isActive: () => boolean\n) => {\n // Start following so a freshly opened, still-growing source pins to its tail\n // even though it usually mounts scrolled to the top.\n const following = ref(true)\n\n const { arrivedState, directions, y } = useScroll(target, {\n onScroll: () => {\n if (directions.top) following.value = false // scrolled up → stop\n else if (arrivedState.bottom) following.value = true // back at bottom → resume\n }\n })\n\n // A wheel-up reaches us even when the target can't scroll (short content, or\n // an auto-height embed where a parent scrolls) — the only \"stop following\"\n // signal available there.\n useEventListener(target, 'wheel', (e: WheelEvent) => { if (e.deltaY < 0) following.value = false }, { passive: true })\n\n const pinToBottom = () => {\n const el = toValue(target)\n if (!el) return\n // For an element, `y` sets its scrollTop; for the window we scroll to the\n // document's full height (window has no scrollHeight of its own).\n y.value = el instanceof Window\n ? (document.scrollingElement ?? document.documentElement).scrollHeight\n : el.scrollHeight\n }\n\n watch(growthSignal, () => { if (isActive() && following.value) pinToBottom() }, { flush: 'post' })\n\n return { following }\n}\n"]}
@@ -26,3 +26,4 @@ export function useConceptFilters(reactiveSearchParams, datasetId) {
26
26
  return conceptFilters;
27
27
  }
28
28
  export default useConceptFilters;
29
+ //# sourceMappingURL=concept-filters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"concept-filters.js","sourceRoot":"","sources":["concept-filters.ts"],"names":[],"mappings":"AAAA,yEAAyE;AAEzE,OAAO,EAAE,QAAQ,EAAE,KA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B,CAAA","sourcesContent":["// filter reactiveSearchParams to conceptFilters (params prefixed by _c_)\n\nimport { reactive, watch } from 'vue'\n\nexport function getConceptFilters (searchParams: Record<string, string>, datasetId?: string) {\n const conceptFilters: Record<string, string> = {}\n\n const datasetFiltersPrefix = datasetId && `_d_${datasetId}_`\n\n for (const key of Object.keys(searchParams)) {\n if (key.startsWith('_c_')) conceptFilters[key] = searchParams[key]\n if (datasetFiltersPrefix && key.startsWith(datasetFiltersPrefix)) {\n conceptFilters[key.replace(datasetFiltersPrefix, '')] = searchParams[key]\n }\n }\n return conceptFilters\n}\n\nexport function useConceptFilters (reactiveSearchParams: Record<string, string>, datasetId?: string) {\n const conceptFilters = reactive({} as Record<string, string>)\n\n // we use a watch and mutations on a reactive to prevent triggering reactivity on unrelated changes in reactive search params\n watch(reactiveSearchParams, () => {\n const newConceptFilters = getConceptFilters(reactiveSearchParams, datasetId)\n Object.assign(conceptFilters, newConceptFilters)\n for (const key of Object.keys(conceptFilters)) {\n if (!(key in newConceptFilters)) delete conceptFilters[key]\n }\n }, { immediate: true })\n\n return conceptFilters\n}\n\nexport default useConceptFilters\n"]}
package/deep-diff.js CHANGED
@@ -20,3 +20,4 @@ export const watchDeepDiff = (source, callback, options) => {
20
20
  callback(newValue, oldValue, onCleanup);
21
21
  }, options);
22
22
  };
23
+ //# sourceMappingURL=deep-diff.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep-diff.js","sourceRoot":"","sources":["deep-diff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAsG,MAAM,KAAK,CAAA;AACzI,OAAO,KAAK,MAAM,iBAAiB,CAAA;AAEnC;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAO,MAA4B,EAAE,OAAyB,EAAE,EAAE;IAChG,OAAO,QAAQ,CAAO,CAAC,QAAQ,EAAE,EAAE;QACjC,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAA;QACzB,OAAO,CAAC,QAAQ,KAAK,SAAS,IAAI,KAAK,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAA;IACpF,CAAC,EAAE,OAAO,CAAC,CAAA;AACb,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,MAAmB,EAAE,QAAuB,EAAE,OAAsB,EAAE,EAAE;IACpG,OAAO,KAAK,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE;QACrD,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,QAAQ,CAAC;YAAE,QAAQ,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAA;IACzE,CAAC,EAAE,OAAO,CAAC,CAAA;AACb,CAAC,CAAA","sourcesContent":["import { computed, watch, type ComputedGetter, type ComputedOptions, type WatchSource, type WatchCallback, type WatchOptions } from 'vue'\nimport equal from 'fast-deep-equal'\n\n/**\n * a computed replacement that returns the old value if the new value only has a superficial \"reference\" change but is actually identitical\n * prevents unnecessary triggers or reactivity\n */\nexport const computedDeepDiff = <Type>(getter: ComputedGetter<Type>, options?: ComputedOptions) => {\n return computed<Type>((oldValue) => {\n const newValue = getter()\n return (oldValue !== undefined && equal(newValue, oldValue)) ? oldValue : newValue\n }, options)\n}\n\n/**\n * a watch replacement the triggers the callback only if the new value is actually different from the old value\n * not just for superficial \"reference\" changes\n */\nexport const watchDeepDiff = (source: WatchSource, callback: WatchCallback, options?: WatchOptions) => {\n return watch(source, (newValue, oldValue, onCleanup) => {\n if (!equal(newValue, oldValue)) callback(newValue, oldValue, onCleanup)\n }, options)\n}\n"]}
package/edit-fetch.js CHANGED
@@ -61,3 +61,4 @@ export function useEditFetch(url, options = {}) {
61
61
  };
62
62
  }
63
63
  export default useEditFetch;
64
+ //# sourceMappingURL=edit-fetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3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AA;QAClF,CAAC;QACD,IAAI,OAAO,CAAC,cAAc,IAAI,CAAC,GAAG,EAAE,CAAC;YACnC,KAAK,CAAC,OAAO,EAAE,CAAA;QACjB,CAAC;aAAM,CAAC;YACN,UAAU,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAA;YAC7B,4DAA4D;YAC5D,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC,CAAA;QAC1D,CAAC;IACH,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAA;IACvB,OAAO;QACL,KAAK;QACL,IAAI;QACJ,UAAU;QACV,OAAO;QACP,IAAI;KACL,CAAA;AACH,CAAC;AAED,eAAe,YAAY,CAAA","sourcesContent":["import { ref, watch, computed, type Ref } from 'vue'\nimport { ofetch } from 'ofetch'\nimport { useFetch, type UseFetchOptions } from './fetch.js'\nimport useAsyncAction, { AsyncActionOptions } from './async-action.js'\nimport equal from 'fast-deep-equal'\nimport clone from '@data-fair/lib-utils/clone.js'\n\ntype UseEditFetchOptions = UseFetchOptions & {\n patch?: boolean\n saveOptions?: AsyncActionOptions\n fetchAfterSave?: boolean\n}\n\ntype OptionalUrl = string | null | undefined\n\nexport function useEditFetch<T extends Record<string, any>> (url: OptionalUrl | Ref<OptionalUrl> | (() => OptionalUrl), options: UseEditFetchOptions = {}) {\n const fetch = useFetch<T>(url, options)\n const serverData = ref<T | null>(null)\n const data = ref<T | null>(null)\n watch(fetch.data, () => {\n // TODO: check for local changes before overwriting ?\n serverData.value = clone(fetch.data.value)\n data.value = clone(fetch.data.value)\n })\n\n const hasDiff = computed(() => !equal(data.value, serverData.value))\n\n const getPatch = (oldData: any, newData: any) => {\n if (!oldData || !newData) return null\n const patch: any = {}\n for (const key of Object.keys(newData)) {\n if (!equal(newData[key], oldData[key])) patch[key] = newData[key]\n }\n for (const key of Object.keys(oldData)) {\n if (!(key in newData)) patch[key] = null\n }\n return patch\n }\n\n const save = useAsyncAction(async () => {\n if (!data.value || !serverData.value || !fetch.data.value) throw new Error('cannot save data that has not been fetched yet')\n let res: T\n const dataBeforeSave = clone(data.value)\n if (options.patch) {\n const patch = getPatch(serverData.value, data.value)\n if (!Object.keys(patch).length) return\n res = await ofetch<T>(fetch.fullUrl.value!, { method: 'PATCH', body: patch })\n } else {\n // TODO: add if-unmodified-since header ?\n res = await ofetch<T>(fetch.fullUrl.value!, { method: 'PUT', body: data.value })\n }\n if (options.fetchAfterSave || !res) {\n fetch.refresh()\n } else {\n serverData.value = clone(res)\n // case of server-side calculated properties, updatedAt, etc\n Object.assign(data.value, getPatch(dataBeforeSave, res))\n }\n }, options.saveOptions)\n return {\n fetch,\n data,\n serverData,\n hasDiff,\n save\n }\n}\n\nexport default useEditFetch\n"]}
package/fetch.js CHANGED
@@ -60,3 +60,4 @@ export function useFetch(url, options = {}) {
60
60
  };
61
61
  }
62
62
  export default useFetch;
63
+ //# sourceMappingURL=fetch.js.map
package/fetch.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.js","sourceRoot":"","sources":["fetch.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAC/B,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAC1F,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAA;AAa3D,MAAM,UAAU,QAAQ,CAAK,GAAkC,EAAE,UAA2B,EAAE;IAC5F,MAAM,EAAE,WAAW,EAAE,GAAG,UAAU,EAAE,CAAA;IAEpC,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,EAAE;QAC5B,IAAI,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;QAC1B,MAAM,OAAO,GAAG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G,GAAG,CAAA;gBACjB,IAAI,OAAO,CAAC,UAAU,KAAK,KAAK,EAAE,CAAC;oBACjC,WAAW,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAA;gBACtC,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,CAAC,KAAK,GAAG,KAAK,CAAA;QACrB,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC,CAAA;IAED,IAAI,OAAO,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;QAC5B,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE;YAClB,IAAI,OAAO,CAAC,SAAS,KAAK,KAAK,IAAI,WAAW,CAAC,KAAK;gBAAE,OAAO,EAAE,CAAA;QACjE,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IACzB,CAAC;IAED,OAAO;QACL,WAAW,EAAE,QAAQ,CAAC,WAAW,CAAC;QAClC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC;QAC1B,IAAI,EAAE,eAAe,CAAC,IAAI,CAAC;QAC3B,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC;QAC1B,KAAK,EAAE,eAAe,CAAC,KAAK,CAAC;QAC7B,OAAO;KACR,CAAA;AACH,CAAC;AAED,eAAe,QAAQ,CAAA","sourcesContent":["import type { QueryObject } from 'ufo'\nimport type { Ref } from 'vue'\nimport { ofetch } from 'ofetch'\nimport { withQuery } from 'ufo'\nimport { computed, watch, ref, shallowRef, readonly, shallowReadonly, toValue } from 'vue'\nimport { useUiNotif } from '@data-fair/lib-vue/ui-notif.js'\nimport { MaybeRefOrGetter } from 'vue'\n\nexport type UseFetchOptions = {\n query?: MaybeRefOrGetter<QueryObject>,\n watch?: Boolean\n notifError?: Boolean\n immediate?: Boolean\n waitFor?: MaybeRefOrGetter<Boolean>\n}\n\ntype OptionalUrl = string | null | undefined\n\nexport function useFetch<T> (url: MaybeRefOrGetter<OptionalUrl>, options: UseFetchOptions = {}): { data: Ref<T | null>, fullUrl: Ref<string | null>, loading: Ref<boolean>, initialized: Ref<boolean>, error: Ref<any>, refresh: (() => Promise<T | null>) } {\n const { sendUiNotif } = useUiNotif()\n\n const fullUrl = computed(() => {\n let fullUrl = toValue(url)\n const waitFor = toValue(options.waitFor)\n if (waitFor === false) return null\n if (!fullUrl) return null\n const query = toValue(options.query)\n if (query) fullUrl = withQuery(fullUrl, query)\n return fullUrl\n })\n\n const data = shallowRef(null) as Ref<T | null>\n const loading = ref(false)\n const initialized = ref(false)\n const error = shallowRef<any>(null)\n\n let abortController: AbortController | undefined\n const refresh = async () => {\n initialized.value = true\n if (!fullUrl.value) return null\n error.value = null\n if (abortController) abortController.abort()\n loading.value = true\n abortController = new AbortController()\n try {\n data.value = await ofetch<T>(fullUrl.value, { signal: abortController.signal })\n } catch (err: any) {\n if (err.name !== 'AbortError' && err.cause?.name !== 'AbortError') {\n error.value = err\n if (options.notifError !== false) {\n sendUiNotif({ msg: '', error: err })\n }\n }\n }\n loading.value = false\n return data.value\n }\n\n if (options.watch !== false) {\n watch(fullUrl, () => {\n if (options.immediate !== false || initialized.value) refresh()\n }, { immediate: true })\n }\n\n return {\n initialized: readonly(initialized),\n fullUrl: readonly(fullUrl),\n data: shallowReadonly(data),\n loading: readonly(loading),\n error: shallowReadonly(error),\n refresh,\n }\n}\n\nexport default useFetch\n"]}
package/format/bytes.js CHANGED
@@ -2,3 +2,4 @@
2
2
  import { formatBytes } from '@data-fair/lib-utils/format/bytes.js';
3
3
  export * from '@data-fair/lib-utils/format/bytes.js';
4
4
  export default formatBytes;
5
+ //# sourceMappingURL=bytes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bytes.js","sourceRoot":"","sources":["bytes.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAA;AAElE,cAAc,sCAAsC,CAAA;AACpD,eAAe,WAAW,CAAA","sourcesContent":["// re-export for retro-compatiblity\nimport { formatBytes } from '@data-fair/lib-utils/format/bytes.js'\n\nexport * from '@data-fair/lib-utils/format/bytes.js'\nexport default formatBytes\n"]}
package/format/field.js CHANGED
@@ -1,2 +1,3 @@
1
1
  // re-export for retro-compatiblity
2
2
  export * from '@data-fair/lib-utils/format/field.js';
3
+ //# sourceMappingURL=field.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field.js","sourceRoot":"","sources":["field.ts"],"names":[],"mappings":"AAAA,mCAAmC;AAEnC,cAAc,sCAAsC,CAAA","sourcesContent":["// re-export for retro-compatiblity\n\nexport * from '@data-fair/lib-utils/format/field.js'\n"]}
package/leave-guard.js CHANGED
@@ -24,3 +24,4 @@ export const useLeaveGuard = (isDirty, options) => {
24
24
  onUnmounted(() => window.removeEventListener('beforeunload', handleWindowClose));
25
25
  };
26
26
  export default useLeaveGuard;
27
+ //# sourceMappingURL=leave-guard.js.map
@@ -0,0 +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;AAOD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAAkC,EAAE,OAA2B,EAAE,EAAE;IAC/F,MAAM,UAAU,GAAG,GAAG,EAAE,CAAC,OAAO,EAAE,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,EAAE,CAAA;IAEtH,mBAAmB;IACnB,kBAAkB,CAAC,GAAG,EAAE;QACtB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;YAAE,OAAM;QAC7B,OAAO,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAA;IACrC,CAAC,CAAC,CAAA;IAEF,gBAAgB;IAChB,MAAM,iBAAiB,GAAG,CAAC,CAAoB,EAAE,EAAE;QACjD,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;YAAE,OAAM;QAC7B,CAAC,CAAC,cAAc,EAAE,CAAA;QAClB,CAAC,CAAC,WAAW,GAAG,UAAU,EAAE,CAAA;IAC9B,CAAC,CAAA;IACD,SAAS,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAC,CAAA;IAC3E,WAAW,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAC,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}\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 return window.confirm(getMessage())\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"]}
@@ -6,3 +6,4 @@ if (import.meta.env?.SSR) {
6
6
  }
7
7
  console.error('locale-dayjs-global is deprecated, please use create + use');
8
8
  export const { locale, dayjs } = getLocaleDayjs();
9
+ //# sourceMappingURL=locale-dayjs-global.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locale-dayjs-global.js","sourceRoot":"","sources":["locale-dayjs-global.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAE1F,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAElD,aAAa;AACb,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC;IACzB,MAAM,IAAI,KAAK,CAAC,0EAA0E,CAAC,CAAA;AAC7F,CAAC;AAED,OAAO,CAAC,KAAK,CAAC,4DAA4D,CAAC,CAAA;AAE3E,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,cAAc,EAAE,CAAA","sourcesContent":["// same as locale-dayjs but in a module level singleton for convenience when not using SSR\n\nimport { getLocaleDayjs } from './locale-dayjs.js'\n\n// @ts-ignore\nif (import.meta.env?.SSR) {\n throw new Error('this module uses a module level singleton, it cannot be used in SSR mode')\n}\n\nconsole.error('locale-dayjs-global is deprecated, please use create + use')\n\nexport const { locale, dayjs } = getLocaleDayjs()\n"]}
package/locale-dayjs.js CHANGED
@@ -37,3 +37,4 @@ export function useLocaleDayjs() {
37
37
  return localeDayjs;
38
38
  }
39
39
  export default useLocaleDayjs;
40
+ //# sourceMappingURL=locale-dayjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locale-dayjs.js","sourceRoot":"","sources":["locale-dayjs.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAA;AAC5B,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,oBAAoB,CAAA;AAC3B,OAAO,o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AC,CAAA;IAC/F,OAAO,WAAgD,CAAA;AACzD,CAAC;AACD,eAAe,cAAc,CAAA","sourcesContent":["// import type { Dayjs, ConfigType } from 'dayjs'\nimport type { App } from 'vue'\nimport { inject } from 'vue'\nimport dayjs from 'dayjs'\nimport 'dayjs/locale/fr.js'\nimport 'dayjs/locale/en.js'\nimport localizedFormat from 'dayjs/plugin/localizedFormat.js'\nimport relativeTime from 'dayjs/plugin/relativeTime.js'\nimport duration, { CreateDurationType } from 'dayjs/plugin/duration.js'\n\nexport type { ConfigType as DayjsConfigType } from 'dayjs'\n\n// for some reason our exported type did not inherit overloads by plugins\n/* type RelativeDayjs = Omit<Dayjs, 'add' | 'subtract'> & {\n // copied from relativeTime.d.ts\n fromNow(withoutSuffix?: boolean): string\n from(compared: ConfigType, withoutSuffix?: boolean): string\n toNow(withoutSuffix?: boolean): string\n to(compared: ConfigType, withoutSuffix?: boolean): string\n // copied from duration.d.ts\n add(duration: Duration): RelativeDayjs\n subtract(duration: Duration): RelativeDayjs\n} */\ndeclare module 'dayjs' {\n interface Dayjs {\n fromNow(withoutSuffix?: boolean): string\n from(compared: ConfigType, withoutSuffix?: boolean): string\n toNow(withoutSuffix?: boolean): string\n to(compared: ConfigType, withoutSuffix?: boolean): string\n }\n}\n\ndayjs.extend(localizedFormat)\ndayjs.extend(relativeTime)\ndayjs.extend(duration)\n\n// main functionality, use through the createLocaleDayjs plugin and useLocaleDayjs composable\n// or as a global singleton through ./locale-dayjs-global.js\nexport function getLocaleDayjs (locale?: string) {\n locale = locale ?? 'fr'\n return {\n locale,\n duration: ((...args) => {\n // @ts-ignore\n return dayjs.duration(...args).locale(locale)\n }) as CreateDurationType,\n dayjs: ((...args) => {\n // @ts-ignore\n return dayjs(...args).locale(locale)\n }) as typeof dayjs\n }\n}\n\n// uses pattern for SSR friendly plugin/composable, cf https://antfu.me/posts/composable-vue-vueday-2021#shared-state-ssr-friendly\nexport const localeDayjsKey = Symbol('localeDayjs')\nexport function createLocaleDayjs (locale?: string) {\n const localeDayjs = getLocaleDayjs(locale)\n return { install (app: App) { app.provide(localeDayjsKey, localeDayjs) } }\n}\nexport function useLocaleDayjs () {\n const localeDayjs = inject(localeDayjsKey)\n if (!localeDayjs) throw new Error('useLocaleDayjs requires using the plugin createLocaleDayjs')\n return localeDayjs as ReturnType<typeof getLocaleDayjs>\n}\nexport default useLocaleDayjs\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-fair/lib-vue",
3
- "version": "1.27.2",
3
+ "version": "1.28.0",
4
4
  "description": "Composables and other utilities for Vue applications in the data-fair stack.",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -15,6 +15,7 @@
15
15
  "build": "cd .. && npm run build"
16
16
  },
17
17
  "peerDependencies": {
18
+ "@vueuse/core": ">=10",
18
19
  "dayjs": "1",
19
20
  "ofetch": "1",
20
21
  "reconnecting-websocket": "4",
@@ -22,6 +23,9 @@
22
23
  "vue-router": "4 || 5"
23
24
  },
24
25
  "peerDependenciesMeta": {
26
+ "@vueuse/core": {
27
+ "optional": true
28
+ },
25
29
  "reconnecting-websocket": {
26
30
  "optional": true
27
31
  },
@@ -5,3 +5,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
7
  export default getReactiveSearchParams();
8
+ //# sourceMappingURL=reactive-search-params-global.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactive-search-params-global.js","sourceRoot":"","sources":["reactive-search-params-global.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAE3G,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAA;AAErE,aAAa;AACb,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC;IACzB,MAAM,IAAI,KAAK,CAAC,0EAA0E,CAAC,CAAA;AAC7F,CAAC;AAED,eAAe,uBAAuB,EAAE,CAAA","sourcesContent":["// same as use-reactive-search-params.js but in a module level singleton for convenience when not using SSR\n\nimport { getReactiveSearchParams } from './reactive-search-params.js'\n\n// @ts-ignore\nif (import.meta.env?.SSR) {\n throw new Error('this module uses a module level singleton, it cannot be used in SSR mode')\n}\n\nexport default getReactiveSearchParams()\n"]}
@@ -153,3 +153,4 @@ export const useStringsArraySearchParam = (key, options = {}) => {
153
153
  });
154
154
  };
155
155
  export default useReactiveSearchParams;
156
+ //# sourceMappingURL=reactive-search-params.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactive-search-params.js","sourceRoot":"","sources":["reactive-search-params.ts"],"names":[],"mappings":"AAAA,wHAAwH;AACxH,6FAA6F;AAG7F,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAA;AACvD,OAAO,KAAK,MAAM,OAAO,CAAA;AAQzB,MAAM,KAAK,GAAG,KAAK,CAAC,wBAAwB,CAAC,CAAA;AAC7C,KAAK,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;AAErC,MAAM,iBAAiB,GAAG,CAAC,KAA6B,EAAE,WAA8D,EAAE,EAAE;IAC1H,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;IAC9C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;QAC3C,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,CAAA;QAC9B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;YAClB,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QACxB,CAAC;QACD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM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ueuse/vueuse/blob/main/packages/core/useUrlSearchParams/index.ts)\n// but even simpler, without array values, always in history mode, and shared in a app plugin\n\nimport type { App, ShallowRef } from 'vue'\nimport { reactive, watch, inject, computed } from 'vue'\nimport Debug from 'debug'\n\n// minimal structural type compatible with both vue-router v4 and v5\ninterface ReactiveSearchParamsRouter {\n currentRoute: ShallowRef<{ query: Record<string, string | null | (string | null)[]> }>\n replace: (to: { query: Record<string, string> }) => unknown\n}\n\nconst debug = Debug('reactive-search-params')\ndebug.log = console.log.bind(console)\n\nconst applySearchParams = (state: Record<string, string>, queryParams: Record<string, string | null | (string | null)[]>) => {\n const unusedKeys = new Set(Object.keys(state))\n for (const key of Object.keys(queryParams)) {\n const value = queryParams[key]\n if (typeof value === 'string') {\n state[key] = value\n unusedKeys.delete(key)\n }\n if (Array.isArray(value)) {\n const lastValue = value[value.length - 1]\n if (typeof lastValue === 'string') {\n state[key] = lastValue\n unusedKeys.delete(key)\n }\n }\n }\n for (const unusedKey of unusedKeys) {\n delete state[unusedKey]\n }\n}\n\nexport function getReactiveSearchParams (router?: ReactiveSearchParamsRouter): Record<string, string> {\n // @ts-ignore\n if (!import.meta.env?.SSR && !router) {\n try {\n // nuxt 3 way of reading router\n // @ts-ignore\n\n router = __unctx__.get('nuxt-app').use().$router\n debug('using nuxt 3 router implicitly')\n } catch (e) {\n // nothing to do\n }\n }\n\n const state = reactive({} as Record<string, string>)\n\n // 2 modes, 1 based on vue router, 1 based on window.location.search\n if (router) {\n debug('initialize reactive search params based on vue router')\n watch(router.currentRoute, (route) => {\n debug('route.query changed', route.query)\n applySearchParams(state, route.query)\n }, { immediate: true })\n\n watch(state, () => {\n debug('state changed', state)\n router?.replace({ query: state })\n })\n } else {\n debug('initialize reactive search params based on window.location.search')\n window.addEventListener('popstate', () => {\n debug('update state based on window.location.search', window.location.search)\n applySearchParams(state, Object.fromEntries(new URLSearchParams(window.location.search)))\n })\n applySearchParams(state, Object.fromEntries(new URLSearchParams(window.location.search)))\n\n const updateUrl = () => {\n debug('update url based on state', state)\n const params = new URLSearchParams('')\n for (const key of Object.keys(state)) {\n const value = state[key]\n if (value !== null && value !== undefined && value !== '') {\n params.set(key, value)\n }\n }\n const newQuery = params.toString()\n const newSearch = newQuery.length > 0 ? '?' + newQuery : ''\n if (newSearch !== window.location.search) {\n window.history.replaceState(\n window.history.state,\n window.document.title,\n window.location.pathname + newSearch\n )\n }\n }\n\n watch(state, () => {\n updateUrl()\n })\n }\n\n return state\n}\n\n// uses pattern for SSR friendly plugin/composable, cf https://antfu.me/posts/composable-vue-vueday-2021#shared-state-ssr-friendly\nexport const reactiveSearchParamsKey = Symbol('reactiveSearchParams')\n\nexport function createReactiveSearchParams (router?: ReactiveSearchParamsRouter) {\n const reactiveSearchParams = getReactiveSearchParams(router)\n return {\n install (app: App) { app.provide(reactiveSearchParamsKey, reactiveSearchParams) },\n state: reactiveSearchParams\n }\n}\nexport function useReactiveSearchParams () {\n const reactiveSearchParams = inject(reactiveSearchParamsKey)\n if (!reactiveSearchParams) throw new Error('useReactiveSearchParams requires using the plugin createReactiveSearchParams')\n return reactiveSearchParams as ReturnType<typeof getReactiveSearchParams>\n}\n\nexport const useStringSearchParam = (key: string, options: string | { default?: string } = {}) => {\n const reactiveSearchParams = useReactiveSearchParams()\n const defaultValue = typeof options === 'string' ? options : (options.default ?? '')\n return computed({\n get: () => reactiveSearchParams[key] ?? defaultValue,\n set: (value) => {\n if (value === defaultValue) delete reactiveSearchParams[key]\n else reactiveSearchParams[key] = value\n }\n })\n}\n\nexport const useBooleanSearchParam = (key: string, options: boolean | { default?: boolean, strings?: [string, string] } = {}) => {\n const reactiveSearchParams = useReactiveSearchParams()\n const defaultValue = typeof options === 'boolean' ? options : (options.default ?? false)\n const strings = (typeof options !== 'boolean' && options.strings) || ['1', '0']\n return computed({\n get: () => key in reactiveSearchParams ? (reactiveSearchParams[key] === strings[0] || reactiveSearchParams[key] === 'true') : defaultValue,\n set: (value) => {\n if (value === defaultValue) delete reactiveSearchParams[key]\n else reactiveSearchParams[key] = value ? strings[0] : strings[1]\n }\n })\n}\n\nexport const useNumberSearchParam = (key: string) => {\n const reactiveSearchParams = useReactiveSearchParams()\n return computed({\n get: () => {\n if (key in reactiveSearchParams) {\n const value = Number(reactiveSearchParams[key])\n if (!isNaN(value)) return value\n }\n return null\n },\n set: (value) => {\n if (value === null) delete reactiveSearchParams[key]\n else reactiveSearchParams[key] = '' + value\n }\n })\n}\n\nexport const useStringsArraySearchParam = (key: string, options: 'csv' | { style?: 'csv' } = {}) => {\n const reactiveSearchParams = useReactiveSearchParams()\n // const style = typeof options === 'string' ? options : (options.style ?? 'csv')\n return computed({\n get: () => reactiveSearchParams[key] ? reactiveSearchParams[key]?.split(',') : [],\n set: (value) => {\n if (value.length === 0) delete reactiveSearchParams[key]\n else reactiveSearchParams[key] = value.join(',')\n }\n })\n}\n\nexport default useReactiveSearchParams\n"]}
package/session.js CHANGED
@@ -398,3 +398,4 @@ export function useSessionAuthenticated(errorBuilder) {
398
398
  return session;
399
399
  }
400
400
  export default useSession;
401
+ //# sourceMappingURL=session.js.map
package/session.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources":["session.ts"],"names":[],"mappings":"AACA,OAAO,EAAwC,eAAe,EAAE,MAAM,KAAK,CAAA;AAC3E,OAAO,EAAE,UAAU,EAAc,MAAM,QAAQ,CAAA;AAK/C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAA;AAClF,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,aAAa,MAAM,kBAAkB,CAAA;AAC5C,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,QAAQ,MAAM,mCAAmC,CAAA;AAExD,cAAc,8CAA8C,CAAA;A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AAA,CAAC,CAAC;KACxD,CAAA;AACH,CAAC;AACD,MAAM,UAAU,UAAU;IACxB,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,CAAA;IAClC,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAA;IACnF,OAAO,OAAkB,CAAA;AAC3B,CAAC;AACD,MAAM,UAAU,uBAAuB,CAAE,YAAwB;IAC/D,MAAM,OAAO,GAAG,UAAU,EAAE,CAAA;IAC5B,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QACxB,IAAI,YAAY;YAAE,MAAM,YAAY,EAAE,CAAA;;YACjC,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAA;IAC3E,CAAC;IACD,OAAO,OAA+B,CAAA;AACxC,CAAC;AAED,eAAe,UAAU,CAAA","sourcesContent":["import { type IncomingMessage } from 'node:http'\nimport { type Ref, type ComputedRef, type App, shallowReadonly } from 'vue'\nimport { FetchError, type fetch } from 'ofetch'\n\n// minimal structural type compatible with both vue-router v4 and v5\ninterface RouteLocationLike { fullPath: string }\nimport { type AccountKeys, type SessionState, type SessionStateAuthenticated, type User } from '@data-fair/lib-common-types/session/index.js'\nimport { reactive, computed, watch, inject, ref, shallowRef, readonly } from 'vue'\nimport { ofetch } from 'ofetch'\nimport { jwtDecode } from 'jwt-decode'\nimport cookiesModule from 'universal-cookie'\nimport Debug from 'debug'\nimport inIframe from '@data-fair/lib-utils/in-iframe.js'\n\nexport * from '@data-fair/lib-common-types/session/index.js'\n\nconst Cookies = cookiesModule as unknown as typeof cookiesModule.default\n\ninterface GenericCookies {\n get: (key: string) => string | undefined\n set: (key: string, value: string, options?: Record<string, any>) => void\n remove: (key: string) => void\n}\n\nexport interface SessionOptions {\n sitePath: string\n directoryUrl: string\n defaultLang: string\n route?: RouteLocationLike\n logoutRedirectUrl?: string\n req?: IncomingMessage\n cookies?: GenericCookies\n customFetch?: typeof fetch\n siteInfo?: boolean\n}\n\nexport interface Colors {\n background: string\n 'on-background': string\n surface: string\n 'on-surface': string\n primary: string\n 'on-primary': string\n 'text-primary': string\n secondary: string\n 'on-secondary': string\n 'text-secondary': string\n error: string\n 'on-error': string\n info: string\n 'on-info': string\n success: string\n 'on-success': string\n warning: string\n 'on-warning': string\n admin: string\n 'on-admin': string\n}\n\ninterface FullSiteInfo {\n main?: boolean\n theme: {\n logo?: string\n colors: Colors\n dark: boolean\n darkColors?: Colors\n hc: boolean\n hcColors?: Colors\n hcDark: boolean\n hcDarkColors?: Colors\n }\n}\n\nexport interface SiteInfo {\n main?: boolean\n isAccountMain?: boolean\n authMode: string\n authOnlyOtherSite?: string\n logo?: string\n dark?: boolean\n colors: Colors\n owner: AccountKeys\n}\n\ntype Theme = 'default' | 'dark' | 'hc' | 'hc-dark'\n\nexport interface Session {\n state: SessionState\n user: ComputedRef<SessionState['user']>\n organization: ComputedRef<SessionState['organization']>\n account: ComputedRef<SessionState['account']>\n accountRole: ComputedRef<SessionState['accountRole']>\n siteRole: ComputedRef<SessionState['siteRole']>\n lang: ComputedRef<SessionState['lang']>\n theme: Ref<null | Theme>\n site: Ref<SiteInfo | null>\n fullSite: Ref<FullSiteInfo | null>\n loginUrl: (redirect?: string, extraParams?: Record<string, string>, immediateRedirect?: true) => string\n login: (redirect?: string, extraParams?: Record<string, string>, immediateRedirect?: true) => void\n logout: (redirect?: string) => Promise<void>\n switchOrganization: (org: string | null, dep?: string, role?: string, updateState?: boolean) => void\n setAdminMode: (adminMode: boolean, redirect?: string) => Promise<void>\n asAdmin: (user: any | null) => Promise<void>\n cancelDeletion: () => Promise<void>\n keepalive: () => Promise<void>\n refreshSiteInfo: () => Promise<void>\n switchTheme: (value: Theme) => void\n switchLang: (value: string) => void\n topLocation: Ref<Location | undefined>\n options: SessionOptions\n}\n\nexport type SessionAuthenticated = Omit<Session, 'state' | 'user' | 'account' | 'accountRole'> & {\n state: SessionStateAuthenticated\n user: ComputedRef<SessionStateAuthenticated['user']>\n account: ComputedRef<SessionStateAuthenticated['account']>\n accountRole: ComputedRef<SessionStateAuthenticated['accountRole']>\n}\n\nconst debug = Debug('session')\ndebug.log = console.log.bind(console)\n\nfunction getDefaultTheme (site: FullSiteInfo): Theme {\n // see https://www.scottohara.me/blog/2021/10/01/detect-high-contrast-and-dark-modes.html\n const preferDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches\n const preferHC = window.matchMedia && window.matchMedia('(forced-colors: active)').matches\n if (site.theme.hcDark && preferDark && preferHC) return 'hc-dark'\n if (site.theme.hc && preferHC) return 'hc'\n if (site.theme.dark && preferDark) return 'dark'\n return 'default'\n}\n\nfunction jwtDecodeAlive (jwt: string | null): User | undefined {\n if (!jwt) return\n const decoded = jwtDecode(jwt) as any\n if (!decoded) return\n const now = Math.ceil(Date.now().valueOf() / 1000)\n if (typeof decoded.exp !== 'undefined' && decoded.exp < now) {\n // token expired\n return\n }\n if (typeof decoded.nbf !== 'undefined' && decoded.nbf > now) {\n console.warn(`token not yet valid: ${decoded.nbf}>${now}, ${JSON.stringify(decoded)}`)\n // do not return here, this is probably a false flag due to a slightly mismatched clock\n }\n return decoded as User\n}\n\nconst getTopLocation = () => {\n try {\n return window.top ? window.top.location : window.location\n } catch (err) {\n return window.location\n }\n}\n\nconst goTo = (url: string | null) => {\n const topLocation = getTopLocation()\n if (topLocation == null) {\n throw new TypeError('session.goTo was called without access to the window object or its location')\n }\n if (url) topLocation.href = url\n else topLocation.reload()\n}\n\nconst defaultOptions = { directoryUrl: '/simple-directory', sitePath: '', defaultLang: 'fr' }\n\nexport async function getSession (initOptions: Partial<SessionOptions>): Promise<Session> {\n const options = { ...defaultOptions, ...initOptions }\n const cookiesPath = options.sitePath + '/'\n debug(`init directoryUrl=${options.directoryUrl}, cookiesPath=${cookiesPath}`)\n const ssr = !!options.req\n if (ssr) debug('run in SSR context')\n\n const customFetch = initOptions?.customFetch ?? ofetch\n\n // use vue-router to detect page change and maintain a reference to the current page location\n // top page if we are in iframe context\n const topLocation = computed(() => {\n if (ssr) return undefined\n\n if (options.route?.fullPath) { /* empty */ } // adds reactivity\n const location = getTopLocation()\n debug('update location based on route change', location)\n return location\n })\n\n // the core state of the session that is filled by reading cookies\n const state = reactive({} as SessionState)\n const fullSite = shallowRef<FullSiteInfo | null>(null)\n const site = shallowRef<SiteInfo | null>(null)\n const theme = ref<Theme | null>(null)\n\n // cookies are the source of truth and this information is transformed into the state reactive object\n const cookies = initOptions?.cookies ?? new Cookies(options.req?.headers.cookie)\n const readState = () => {\n theme.value = cookies.get('theme') ?? null\n\n const langCookie = cookies.get('i18n_lang')\n state.lang = langCookie ?? options.defaultLang\n\n const idToken = cookies.get('id_token')\n const user = jwtDecodeAlive(idToken)\n\n if (!user) {\n delete state.user\n delete state.organization\n delete state.account\n delete state.accountRole\n return\n }\n\n // this is to prevent null values that are put by SD versions that do not strictly respect their schema\n for (const org of user.organizations) {\n if (!org.department) {\n delete org.department\n delete org.departmentName\n }\n }\n\n state.user = user\n const organizationId = cookies.get('id_token_org')\n const departmentId = cookies.get('id_token_dep')\n const switchedRole = cookies.get('id_token_role')\n if (organizationId) {\n state.organization = state.user.organizations.find(o => {\n if (o.id !== organizationId) return false\n if (departmentId && departmentId !== o.department) return false\n if (switchedRole && switchedRole !== o.role) return false\n return true\n })\n } else {\n delete state.organization\n }\n if (state.organization) {\n state.account = {\n type: 'organization',\n id: state.organization.id,\n name: state.organization.name,\n department: state.organization.department,\n departmentName: state.organization.departmentName\n }\n state.accountRole = state.organization.role\n } else {\n state.account = {\n type: 'user',\n id: state.user.id,\n name: state.user.name\n }\n state.accountRole = 'admin'\n }\n\n if (state.user?.siteOwner) {\n if (state.user.siteOwner.type === 'user' && state.user.siteOwner.id === state.user.id) {\n state.siteRole = 'admin'\n }\n if (state.user.siteOwner.type === 'organization' && state.user.siteOwner.id === state.organization?.id) {\n state.siteRole = state.organization.role\n }\n }\n }\n readState()\n debug('initial state', state)\n\n if (!ssr) {\n // sessionData is also stored in localStorage as a way to access it in simpler pages that do not require use-session\n // and in order to listen to storage event from other contexts and sync session info accross windows and tabs\n const storageListener = (event: StorageEvent) => {\n if (event.key === 'sd-session' + options.sitePath) readState()\n }\n window.addEventListener('storage', storageListener)\n\n // we cannot use onUnmounted here or we get warnings \"onUnmounted is called when there is no active component instance to be associated with. \"\n // TODO: should we have another cleanup mechanism ?\n // onUnmounted(() => { window.removeEventListener('storage', storageListener) })\n\n // trigger some full page refresh when some key session elements are changed\n // the danger of simply using reactivity is too high, data must be re-fetched, etc.\n watch(() => state.account, (account, oldAccount) => {\n if (account?.type !== oldAccount?.type || account?.id !== oldAccount?.id || account?.department !== oldAccount?.department) {\n goTo(null)\n }\n })\n watch(() => state.lang, () => {\n goTo(null)\n })\n watch(() => state.dark, () => {\n goTo(null)\n })\n watch(state, (state) => {\n if (!ssr) {\n window.localStorage.setItem('sd-session' + options.sitePath, JSON.stringify(state))\n }\n debug('state changed', state)\n })\n }\n\n // login can be performed as a simple link (please use target=top) or as a function\n function loginUrl (redirect?: string, extraParams: Record<string, string> = {}, immediateRedirect = true): string {\n // login can also be used to redirect user immediately if he is already logged\n if (redirect && state.user && immediateRedirect) return redirect\n if (!redirect && topLocation.value) redirect = topLocation.value.href\n let url = `${options.directoryUrl}/login?redirect=${encodeURIComponent(redirect ?? '')}`\n Object.keys(extraParams).filter(key => ![null, undefined, ''].includes(extraParams[key])).forEach((key) => {\n url += `&${key}=${encodeURIComponent(extraParams[key])}`\n })\n return url\n }\n const login = (redirect?: string, extraParams: Record<string, string> = {}, immediateRedirect = true) => {\n goTo(loginUrl(redirect, extraParams, immediateRedirect))\n }\n const logout = async (redirect?: string) => {\n await customFetch(`${options.directoryUrl}/api/auth`, { method: 'DELETE' })\n // sometimes server side cookie deletion is not applied immediately in browser local js context\n // so we do it here to\n cookies.remove('id_token')\n cookies.remove('id_token_org')\n cookies.remove('id_token_dep')\n cookies.remove('id_token_role')\n goTo(redirect ?? options.logoutRedirectUrl ?? null)\n }\n\n const switchOrganization = (org: string | null, dep?: string, role?: string, updateState = true) => {\n const cookieOpts = { path: cookiesPath }\n if (org) cookies.set('id_token_org', org, cookieOpts)\n else cookies.remove('id_token_org', cookieOpts)\n if (dep) cookies.set('id_token_dep', dep, cookieOpts)\n else cookies.remove('id_token_dep', cookieOpts)\n if (role) cookies.set('id_token_role', role, cookieOpts)\n else cookies.remove('id_token_role', cookieOpts)\n if (updateState) readState()\n }\n\n const setAdminMode = async (adminMode: boolean, redirect?: string) => {\n if (adminMode) {\n const params: Record<string, string> = { adminMode: 'true' }\n if (state.user != null) params.email = state.user.email\n // preserve current active org/dep\n if (state.organization) {\n params.org = state.organization.id\n if (state.organization.department) params.dep = state.organization.department\n }\n const url = loginUrl(redirect, params, true)\n goTo(url)\n } else {\n await customFetch(`${options.directoryUrl}/api/auth/adminmode`, { method: 'DELETE' })\n goTo(redirect ?? null)\n }\n }\n\n const asAdmin = async (user: any | null) => {\n if (user) {\n await customFetch(`${options.directoryUrl}/api/auth/asadmin`, { method: 'POST', body: user })\n } else {\n await customFetch(`${options.directoryUrl}/api/auth/asadmin`, { method: 'DELETE' })\n }\n goTo(null)\n }\n\n const cancelDeletion = async () => {\n if (state.user == null) return\n await customFetch(`${options.directoryUrl}/api/users/${state.user.id}`, { method: 'PATCH', body: ({ plannedDeletion: null }) as any })\n readState()\n }\n\n const switchLang = (value: string) => {\n const maxAge = 60 * 60 * 24 * 365 // 1 year\n cookies.set('i18n_lang', value, { maxAge, path: cookiesPath })\n goTo(null)\n }\n\n const switchTheme = (value: Theme) => {\n const maxAge = 60 * 60 * 24 * 365 // 1 year\n cookies.set('theme', value, { maxAge, path: cookiesPath })\n goTo(null)\n }\n\n const keepalive = async () => {\n // check cookies.get('id_token') not state.user so that we do a keepalive on expired id tokens\n // as we might have an exchange token\n if (!cookies.get('id_token')) return\n if (!ssr) {\n window.localStorage.setItem('sd-keepalive' + options.sitePath, `${new Date().getTime()}`)\n }\n try {\n await customFetch(`${options.directoryUrl}/api/auth/keepalive`, { method: 'POST' })\n } catch (err) {\n if (err instanceof FetchError && err.statusCode === 401) {\n console.warn('session was expired or deleted server side')\n } else {\n throw err\n }\n }\n readState()\n }\n\n const refreshSiteInfo = async () => {\n console.warn('@data-fair/lib-vue/session refreshSiteInfo is deprecated')\n const siteInfo = await customFetch(`${options.directoryUrl}/api/sites/_public`)\n setSiteInfo(siteInfo)\n }\n\n const setSiteInfo = (siteInfo: any) => {\n if (siteInfo.theme) {\n fullSite.value = siteInfo\n const partialSite: SiteInfo = {\n main: siteInfo.main,\n isAccountMain: siteInfo.isAccountMain,\n logo: siteInfo.theme.logo,\n colors: siteInfo.theme.colors,\n authMode: siteInfo.authMode,\n authOnlyOtherSite: siteInfo.authOnlyOtherSite,\n owner: siteInfo.owner\n }\n if (theme.value == null) theme.value = getDefaultTheme(siteInfo)\n if (theme.value === 'hc') partialSite.colors = siteInfo.theme.hcColors\n if (theme.value === 'dark') {\n partialSite.colors = siteInfo.theme.darkColors\n partialSite.dark = true\n }\n if (theme.value === 'hc-dark') {\n partialSite.colors = siteInfo.theme.hcDarkColors\n partialSite.dark = true\n }\n site.value = partialSite\n } else {\n site.value = siteInfo\n }\n }\n\n if (options.siteInfo) await refreshSiteInfo()\n\n // @ts-ignore\n if (!ssr && window.__PUBLIC_SITE_INFO) setSiteInfo(window.__PUBLIC_SITE_INFO)\n\n // immediately performs a keepalive, but only on top windows (not iframes or popups)\n // and only if it was not done very recently (maybe from a refreshed page next to this one)\n // also run an auto-refresh loop\n if (!ssr && !inIframe && !('triggerCapture' in window)) {\n const lastKeepalive = window.localStorage.getItem('sd-keepalive' + options.sitePath)\n\n if (!lastKeepalive || (new Date().getTime() - Number(lastKeepalive)) > 10000) {\n await keepalive()\n }\n\n const refreshLoopDelay = 10 * 60 * 1000 // 10 minutes\n setInterval(() => {\n const lastKeepalive = window.localStorage.getItem('sd-keepalive' + options.sitePath)\n if (!lastKeepalive || (new Date().getTime() - Number(lastKeepalive)) > refreshLoopDelay / 2) {\n keepalive().catch(err => console.error(err))\n }\n }, refreshLoopDelay)\n }\n\n const session: Session = {\n state,\n organization: computed(() => state.organization),\n user: computed(() => state.user),\n account: computed(() => state.account),\n accountRole: computed(() => state.accountRole),\n siteRole: computed(() => state.siteRole),\n lang: computed(() => state.lang),\n theme: readonly(theme),\n site: shallowReadonly(site),\n fullSite: shallowReadonly(fullSite),\n loginUrl,\n login,\n logout,\n switchOrganization,\n setAdminMode,\n asAdmin,\n cancelDeletion,\n keepalive,\n refreshSiteInfo,\n switchTheme,\n switchLang,\n topLocation,\n options\n }\n\n return session\n}\n\n// uses pattern for SSR friendly plugin/composable, cf https://antfu.me/posts/composable-vue-vueday-2021#shared-state-ssr-friendly\nexport const sessionKey = Symbol('session')\nexport async function createSession (initOptions: Partial<SessionOptions>) {\n const session = await getSession(initOptions)\n return {\n ...session,\n install (app: App) { app.provide(sessionKey, session) },\n }\n}\nexport function useSession () {\n const session = inject(sessionKey)\n if (!session) throw new Error('useSession requires using the plugin createSession')\n return session as Session\n}\nexport function useSessionAuthenticated (errorBuilder?: () => any) {\n const session = useSession()\n if (!session.state.user) {\n if (errorBuilder) throw errorBuilder()\n else throw new Error('useSessionAuthenticated requires a logged in user')\n }\n return session as SessionAuthenticated\n}\n\nexport default useSession\n"]}
package/ui-notif.js CHANGED
@@ -91,3 +91,4 @@ export function withUiNotif(fn, errorMsg, successNotif) {
91
91
  }
92
92
  };
93
93
  }
94
+ //# sourceMappingURL=ui-notif.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ui-notif.js","sourceRoot":"","sources":["ui-notif.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,+GAA+G;AAC/G,qEAAqE;AAGrE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,KAAK,CAAA;AACxC,OAAO,QAAQ,MAAM,mCAAmC,CAAA;AA0BxD,MAAM,UAAU,YAAY,CAAE,KAAU;IACtC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE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,EAAE,CAAA;IAC5B,OAAO,EAAE,OAAO,CAAE,GAAQ,IAAI,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA,CAAC,CAAC,EAAE,CAAA;AACpE,CAAC;AACD,MAAM,UAAU,UAAU;IACxB,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,CAAA;IAClC,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAA;IACnF,OAAO,OAAwC,CAAA;AACjD,CAAC;AACD,eAAe,UAAU,CAAA;AAEzB,MAAM,UAAU,WAAW,CAA8C,EAAK,EAAE,QAAiB,EAAE,YAA6B;IAC9H,MAAM,EAAE,WAAW,EAAE,GAAG,UAAU,EAAE,CAAA;IACpC,OAAO,CAAC,IAAI,CAAC,uDAAuD,CAAC,CAAA;IACrE,OAAW,KAAK,WAAW,GAAG,IAAW;QACvC,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,CAAA;YAChC,IAAI,YAAY;gBAAE,WAAW,CAAC,YAAY,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC,CAAA;YACpE,OAAO,MAAM,CAAA;QACf,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,WAAW,CAAC,EAAE,GAAG,EAAE,QAAQ,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;QAC7C,CAAC;IACH,CAAC,CAAA;AACH,CAAC","sourcesContent":["// simple composable to display store a UI notification\n// this will be transmitted to frame parent if available (compatible with v-iframe uiNotification message type)\n// or can be displayed locally by @data-fair/lib-vuetify/ui-notif.vue\n\nimport type { App } from 'vue'\nimport { shallowRef, inject } from 'vue'\nimport inIframe from '@data-fair/lib-utils/in-iframe.js'\n\nexport type UiNotif = UiNotifBase | UiNotifError\n\ntype NotifType = 'default' | 'info' | 'success' | 'warning' | 'error'\n\nexport type PartialUiNotif = string | {\n type?: NotifType\n msg: string\n error?: any\n errorMsg?: string\n}\n\ninterface UiNotifBase {\n type?: 'default' | 'info' | 'success' | 'warning'\n msg: string\n}\n\ninterface UiNotifError {\n type: 'error'\n msg: string\n error?: any\n errorMsg: string\n clientError?: boolean\n}\n\nexport function getErrorCode (error: any): number {\n if (typeof error === 'string') return 500\n if (typeof error.statusCode === 'number') return error.statusCode\n if (typeof error.response?.statusCode === 'number') return error.response?.statusCode\n if (typeof error.code === 'number') return error.code\n if (typeof error.response?.code === 'number') return error.response?.code\n return 500\n}\n\nexport function getErrorMsg (error: any): string {\n if (typeof error === 'string') return error\n if (error.data && typeof error.data === 'string') return error.data\n if (error.response?.data && typeof error.response.data === 'string') return error.response.data\n if (error.statusText && typeof error.statusText === 'string') return error.statusText\n if (error.response?.statusText && typeof error.response?.statusText === 'string') return error.response?.statusText\n if (error.message) return error.message\n return 'erreur inconnue'\n}\n\nexport function getFullNotif (notif: PartialUiNotif, defaultType: UiNotifBase['type'] = 'default'): UiNotif {\n if (typeof notif === 'string') return { msg: notif, type: defaultType }\n if (notif.error) {\n const code = getErrorCode(notif.error)\n return {\n ...notif,\n type: 'error',\n errorMsg: getErrorMsg(notif.error),\n clientError: code < 500\n } as UiNotifError\n }\n return {\n ...notif,\n type: notif.type ?? defaultType\n } as UiNotifBase\n}\n\nexport const getUiNotif = () => {\n const notification = shallowRef(null as null | UiNotif)\n function sendUiNotif (partialNotif: PartialUiNotif) {\n const notif = notification.value = getFullNotif(partialNotif)\n if (inIframe) {\n if (notif.type === 'error') delete notif.error\n window.top?.postMessage({ vIframe: true, uiNotification: notif }, '*')\n } else {\n console.log('iframe notification', notif)\n }\n }\n return { notification, sendUiNotif }\n}\n\n// uses pattern for SSR friendly plugin/composable, cf https://antfu.me/posts/composable-vue-vueday-2021#shared-state-ssr-friendly\nexport const uiNotifKey = Symbol('uiNotif')\nexport function createUiNotif () {\n const uiNotif = getUiNotif()\n return { install (app: App) { app.provide(uiNotifKey, uiNotif) } }\n}\nexport function useUiNotif () {\n const uiNotif = inject(uiNotifKey)\n if (!uiNotif) throw new Error('useUiNotif requires using the plugin createUiNotif')\n return uiNotif as ReturnType<typeof getUiNotif>\n}\nexport default useUiNotif\n\nexport function withUiNotif<F extends (...args: any[]) => Promise<any>> (fn: F, errorMsg?: string, successNotif?: PartialUiNotif): F {\n const { sendUiNotif } = useUiNotif()\n console.warn('withUiNotif is deprecated, use useAsyncAction instead')\n return <F> async function (...args: any[]) {\n try {\n const result = await fn(...args)\n if (successNotif) sendUiNotif(getFullNotif(successNotif, 'success'))\n return result\n } catch (error) {\n sendUiNotif({ msg: errorMsg ?? '', error })\n }\n }\n}\n"]}
package/vite.js CHANGED
@@ -57,3 +57,4 @@ export function ClosePlugin() {
57
57
  },
58
58
  };
59
59
  }
60
+ //# sourceMappingURL=vite.js.map
package/vite.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.js","sourceRoot":"","sources":["vite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,KAAK;IACL,UAAU;IACV,YAAY;IACZ;QACE,+BAA+B,EAAE,CAAC,YAAY,EAAE,yBAAyB,CAAC;QAC1E,8CAA8C,EAAE,CAAC,yBAAyB,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,4BAA4B,CAAC;QAClL,oCAAoC,EAAE,CAAC,gBAAgB,CAAC;QACxD,uCAAuC,EAAE,CAAC,mBAAmB,CAAC;QAC9D,gCAAgC,EAAE,CAAC,YAAY,EAAE,aAAa,CAAC;QAC/D,6BAA6B,EAAE,CAAC,UAAU,CAAC;QAC3C,kCAAkC,EAAE,CAAC,cAAc,CAAC;QACpD,0BAA0B,EAAE,CAAC,OAAO,CAAC;QACrC,oCAAoC,EAAE,CAAC,gBAAgB,CAAC;QACxD,mCAAmC,EAAE,CAAC,eAAe,CAAC;QACtD,iCAAiC,EAAE,CAAC,kBAAkB,EAAE,eAAe,CAAC;QACxE,oCAAoC,EAAE,CAAC,aAAa,CAAC;KACtD;CACF,CAAA;AAED,6FAA6F;AAC7F,MAAM,UAAU,WAAW;IACzB,OAAO;QACL,IAAI,EAAE,aAAa,EAAE,gDAAgD;QAErE,yCAAyC;QACzC,QAAQ,CAAE,KAAU;YAClB,IAAI,KAAK,EAAE,CAAC;gBACV,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;gBACpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;YACjB,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;YAC5B,CAAC;QACH,CAAC;QAED,sDAAsD;QACtD,WAAW;YACT,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;YAC5B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACjB,CAAC;KACF,CAAA;AACH,CAAC","sourcesContent":["/**\n * Preset for {@link https://github.com/unplugin/unplugin-auto-import unplugin-auto-import}.\n *\n * Auto-imports Vue, vue-router, vue-i18n built-ins and all data-fair composables\n * so they can be used in `<script setup>` without explicit import statements.\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import { autoImports } from '@data-fair/lib-vue/vite.js'\n * import AutoImport from 'unplugin-auto-import/vite'\n *\n * export default defineConfig({\n * plugins: [\n * AutoImport({ imports: [...autoImports] })\n * ]\n * })\n * ```\n */\nexport const autoImports = [\n 'vue',\n 'vue-i18n',\n 'vue-router',\n {\n '@data-fair/lib-vue/session.js': ['useSession', 'useSessionAuthenticated'],\n '@data-fair/lib-vue/reactive-search-params.js': ['useReactiveSearchParams', 'useStringSearchParam', 'useBooleanSearchParam', 'useNumberSearchParam', 'useStringsArraySearchParam'],\n '@data-fair/lib-vue/locale-dayjs.js': ['useLocaleDayjs'],\n '@data-fair/lib-vue/concept-filters.js': ['useConceptFilters'],\n '@data-fair/lib-vue/ui-notif.js': ['useUiNotif', 'withUiNotif'],\n '@data-fair/lib-vue/fetch.js': ['useFetch'],\n '@data-fair/lib-vue/edit-fetch.js': ['useEditFetch'],\n '@data-fair/lib-vue/ws.js': ['useWS'],\n '@data-fair/lib-vue/async-action.js': ['useAsyncAction'],\n '@data-fair/lib-vue/leave-guard.js': ['useLeaveGuard'],\n '@data-fair/lib-vue/deep-diff.js': ['computedDeepDiff', 'watchDeepDiff'],\n '@data-fair/lib-vue/format/bytes.js': ['formatBytes'],\n }\n]\n\n// cf https://stackoverflow.com/questions/75839993/vite-build-hangs-forever/76920975#76920975\nexport function ClosePlugin () {\n return {\n name: 'ClosePlugin', // required, will show up in warnings and errors\n\n // use this to catch errors when building\n buildEnd (error: any) {\n if (error) {\n console.error(error)\n process.exit(1)\n } else {\n console.log('Build ended')\n }\n },\n\n // use this to catch the end of a build without errors\n closeBundle () {\n console.log('Bundle closed')\n process.exit(0)\n },\n }\n}\n"]}
package/ws.js CHANGED
@@ -64,3 +64,4 @@ export function useWS(path) {
64
64
  return sockets[path];
65
65
  }
66
66
  export default useWS;
67
+ //# sourceMappingURL=ws.js.map
package/ws.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ws.js","sourceRoot":"","sources":["ws.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,MAAM,wBAAwB,CAAA;AAChE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AAGnD,MAAM,qBAAqB,GAAG,2BAAoF,CAAA;AAElH,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,EAAE;IAC7B,IAAI,CAAC,MAAM,CAAC,SAAS;QAAE,OAAM;IAC7B,aAAa;IACb,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG;QAAE,OAAM;IAChC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,MAA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AAM,OAAO,GAA6C,EAAE,CAAA;AAE5D,MAAM,UAAU,KAAK,CAAE,IAAY;IACjC,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,CAAA;IAC5C,OAAO,OAAO,CAAC,IAAI,CAAC,CAAA;AACtB,CAAC;AAED,eAAe,KAAK,CAAA","sourcesContent":["import reconnectingWebSocketModule from 'reconnecting-websocket'\nimport { ref, reactive, onScopeDispose } from 'vue'\nimport type { Message } from '@data-fair/lib-common-types/ws.js'\n\nconst ReconnectingWebSocket = reconnectingWebSocketModule as unknown as typeof reconnectingWebSocketModule.default\n\nconst getWS = (path: string) => {\n if (!window.WebSocket) return\n // @ts-ignore\n if (import.meta.env?.SSR) return\n const url = (window.location.origin + path).replace('http:', 'ws:').replace('https:', 'wss:')\n const ws = new ReconnectingWebSocket(url)\n\n const subscriptions = reactive({} as Record<string, ((message: any) => void)[]>)\n const opened = ref(false)\n\n ws.addEventListener('open', () => {\n opened.value = true\n for (const channel of Object.keys(subscriptions)) {\n if (subscriptions[channel].length) {\n ws.send(JSON.stringify({ type: 'subscribe', channel }))\n } else {\n ws.send(JSON.stringify({ type: 'unsubscribe', channel }))\n delete subscriptions[channel]\n }\n }\n })\n ws.addEventListener('close', () => {\n opened.value = false\n })\n ws.onmessage = (event: any) => {\n const body = JSON.parse(event.data) as Message\n if (body.type === 'message') {\n if (subscriptions[body.channel]?.length) {\n for (const listener of subscriptions[body.channel]) {\n listener(body.data)\n }\n }\n }\n }\n\n function subscribe <T> (channel: string, listener: (message: T) => void) {\n if (!subscriptions[channel]) {\n subscriptions[channel] = []\n if (opened.value) ws.send(JSON.stringify({ type: 'subscribe', channel }))\n }\n subscriptions[channel].push(listener)\n\n onScopeDispose(() => {\n unsubscribe(channel, listener)\n })\n }\n\n const unsubscribe = (channel: string, listener: (message: any) => void) => {\n if (subscriptions[channel]) {\n subscriptions[channel] = subscriptions[channel].filter(l => l !== listener)\n if (subscriptions[channel].length === 0 && opened.value) {\n ws.send(JSON.stringify({ type: 'unsubscribe', channel }))\n delete subscriptions[channel]\n }\n }\n }\n\n return { opened, ws, subscribe, unsubscribe }\n}\n\nconst sockets: Record<string, ReturnType<typeof getWS>> = {}\n\nexport function useWS (path: string) {\n sockets[path] = sockets[path] ?? getWS(path)\n return sockets[path]\n}\n\nexport default useWS\n"]}
@@ -1,9 +0,0 @@
1
- import { computed } from 'vue';
2
- import equal from 'fast-deep-equal';
3
- export const computedDeepDiff = (getter, options) => {
4
- return computed((oldValue) => {
5
- const newValue = getter();
6
- return (oldValue !== undefined && equal(newValue, oldValue)) ? oldValue : newValue;
7
- }, options);
8
- };
9
- export default computedDeepDiff;