@milaboratories/uikit 2.2.64 → 2.2.66

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milaboratories/uikit",
3
- "version": "2.2.64",
3
+ "version": "2.2.66",
4
4
  "type": "module",
5
5
  "main": "dist/pl-uikit.umd.js",
6
6
  "module": "dist/pl-uikit.js",
@@ -35,8 +35,8 @@
35
35
  "svgo": "^3.3.2",
36
36
  "@types/d3": "^7.4.3",
37
37
  "@milaboratories/eslint-config": "^1.0.4",
38
- "@milaboratories/helpers": "^1.6.11",
39
- "@platforma-sdk/model": "^1.27.10"
38
+ "@platforma-sdk/model": "^1.28.1",
39
+ "@milaboratories/helpers": "^1.6.11"
40
40
  },
41
41
  "scripts": {
42
42
  "dev": "vite",
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
2
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M19 4C20.6569 4 22 5.34315 22 7V17C22 18.6569 20.6569 20 19 20H5C3.34315 20 2 18.6569 2 17V7C2 5.34315 3.34315 4 5 4H19ZM19 5.5H5C4.17157 5.5 3.5 6.17157 3.5 7V9.25H16H20.5V7C20.5 6.17157 19.8284 5.5 19 5.5ZM20.5 10.75H16H3.5L3.5 17C3.5 17.8284 4.17157 18.5 5 18.5H19C19.8284 18.5 20.5 17.8284 20.5 17V10.75ZM6 15.75H10V14.25H6V15.75Z" fill="#110529"/>
3
+ </svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none"><path fill="#110529" fill-rule="evenodd" d="M19 4a3 3 0 0 1 3 3v10a3 3 0 0 1-3 3H5a3 3 0 0 1-3-3V7a3 3 0 0 1 3-3zm0 1.5H5A1.5 1.5 0 0 0 3.5 7v2.25h17V7A1.5 1.5 0 0 0 19 5.5m1.5 5.25h-17V17A1.5 1.5 0 0 0 5 18.5h14a1.5 1.5 0 0 0 1.5-1.5zm-14.5 5h4v-1.5H6z" clip-rule="evenodd"/></svg>
@@ -129,6 +129,7 @@
129
129
  "menu": "menu.svg",
130
130
  "minimize": "minimize.svg",
131
131
  "minus": "minus.svg",
132
+ "monetization": "monetization.svg",
132
133
  "more": "more.svg",
133
134
  "paper-clip": "paper-clip.svg",
134
135
  "pause": "pause.svg",
@@ -129,6 +129,7 @@ $icons24: (
129
129
  menu: 'menu.svg',
130
130
  minimize: 'minimize.svg',
131
131
  minus: 'minus.svg',
132
+ monetization: 'monetization.svg',
132
133
  more: 'more.svg',
133
134
  paper-clip: 'paper-clip.svg',
134
135
  pause: 'pause.svg',
@@ -0,0 +1,68 @@
1
+ import type { WatchSource, WatchOptions } from 'vue';
2
+ import { reactive, watch, ref, computed } from 'vue';
3
+ import { exclusiveRequest } from '@milaboratories/helpers';
4
+
5
+ export type FetchResult<V, E = unknown> = {
6
+ loading: boolean;
7
+ value: V | undefined;
8
+ error: E;
9
+ };
10
+
11
+ // TODO Should we keep the old value while fetching the new value?
12
+
13
+ /**
14
+ * Watch any reactive source and perform an asynchronous operation
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * const v = useWatchFetch(
19
+ * watchSource,
20
+ * async (sourceValue) => {
21
+ * return await fetchDataFromApi(sourceValue);
22
+ * }
23
+ * );
24
+ *
25
+ * // Usage in a template
26
+ * <template>
27
+ * <div v-if="v.loading">Loading...</div>
28
+ * <div v-else-if="v.error">Error: {{ v.error.message }}</div>
29
+ * <div v-else>Data: {{ v.value }}</div>
30
+ * </template>
31
+ * ```
32
+ */
33
+ export function useWatchFetch<S, V>(watchSource: WatchSource<S>, doFetch: (s: S) => Promise<V>, watchOptions?: WatchOptions): FetchResult<V> {
34
+ const loadingRef = ref(0);
35
+
36
+ const data = reactive({
37
+ loading: computed(() => loadingRef.value > 0),
38
+ loadingRef,
39
+ value: undefined as V,
40
+ error: undefined,
41
+ }) as FetchResult<V>;
42
+
43
+ const exclusive = exclusiveRequest(doFetch);
44
+
45
+ watch(
46
+ watchSource,
47
+ async (s) => {
48
+ data.error = undefined;
49
+ loadingRef.value++;
50
+ exclusive(s)
51
+ .then((res) => {
52
+ if (res.ok) {
53
+ data.value = res.value;
54
+ }
55
+ })
56
+ .catch((err) => {
57
+ data.value = undefined;
58
+ data.error = err;
59
+ })
60
+ .finally(() => {
61
+ loadingRef.value--;
62
+ });
63
+ },
64
+ Object.assign({ immediate: true, deep: true }, watchOptions ?? {}),
65
+ );
66
+
67
+ return data;
68
+ }
@@ -129,6 +129,7 @@ export const maskIcons24 = [
129
129
  'menu',
130
130
  'minimize',
131
131
  'minus',
132
+ 'monetization',
132
133
  'more',
133
134
  'paper-clip',
134
135
  'pause',
package/src/index.ts CHANGED
@@ -96,6 +96,7 @@ export { useFormState } from './composition/useFormState';
96
96
  export { useQuery } from './composition/useQuery.ts';
97
97
  export { useDraggable } from './composition/useDraggable';
98
98
  export { useComponentProp } from './composition/useComponentProp';
99
+ export * from './composition/useWatchFetch';
99
100
 
100
101
  /**
101
102
  * Utils/Partials