@antify/ui-module 1.9.0 → 1.9.1

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/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@antify/ui-module",
3
3
  "configKey": "uiModule",
4
- "version": "1.9.0",
4
+ "version": "1.9.1",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.3",
7
7
  "unbuild": "2.0.0"
@@ -12,6 +12,16 @@ declare function isFormDisabled(status: Ref | Ref[]): boolean;
12
12
  * Detect if the given queryToWatch changed.
13
13
  */
14
14
  declare function queryChanged(from: LocationQuery, to: LocationQuery, queryToWatch: string | string[]): boolean;
15
+ /**
16
+ * Creates a skeleton ref with flicker protection by prevent switching to fast from true to false.
17
+ *
18
+ * Important, it only watches the pending ref once, because a skeleton should be shown only one time
19
+ * on initial loading.
20
+ *
21
+ * @param pending
22
+ * @deprecated - Flicker protection is implemented in @antify/ui directly. Do not handle it from outside anymore.
23
+ */
24
+ declare function createSkeleton(pending: Ref<boolean>): Ref<boolean>;
15
25
  export type CrudRoutingOptions = {
16
26
  detailRouteName: string;
17
27
  listingRouteName: string;
@@ -74,6 +84,7 @@ export declare const useUiClient: () => {
74
84
  goToDetailSubPage(subRouteNameExtension: string, query?: LocationQueryRaw): Promise<void | import("vue-router").NavigationFailure | undefined>;
75
85
  };
76
86
  useFormField: typeof useFormField;
87
+ createSkeleton: typeof createSkeleton;
77
88
  };
78
89
  };
79
90
  export {};
@@ -5,9 +5,11 @@ import {
5
5
  useRouter,
6
6
  useRoute,
7
7
  computed,
8
- reactive
8
+ reactive,
9
+ ref
9
10
  } from "#imports";
10
11
  import { InputState } from "@antify/ui";
12
+ import { watchOnce } from "@vueuse/core";
11
13
  async function handleNotFoundResponse(response, fallbackUrl) {
12
14
  if (response._data?.notFound) {
13
15
  useNuxtApp().$uiModule.toaster.toastError("Entity not found. Maybe an other user deleted it.");
@@ -35,6 +37,23 @@ function queryChanged(from, to, queryToWatch) {
35
37
  }, {});
36
38
  return _queryToWatch.some((key) => changes[key] !== void 0);
37
39
  }
40
+ function createSkeleton(pending) {
41
+ const skeleton = ref(true);
42
+ const initialTimestamp = Date.now();
43
+ const minShowTime = 500;
44
+ watchOnce(pending, () => {
45
+ const timeShowed = Date.now() - (initialTimestamp || Date.now());
46
+ const restTimeToShow = minShowTime - timeShowed > 0 ? minShowTime - timeShowed : 0;
47
+ if (restTimeToShow === 0) {
48
+ skeleton.value = false;
49
+ } else {
50
+ setTimeout(() => {
51
+ skeleton.value = false;
52
+ }, restTimeToShow);
53
+ }
54
+ });
55
+ return skeleton;
56
+ }
38
57
  const useCrudRouting = (detailRouteName, listingRouteName, getDetailRouteParams = () => ({}), getListingRouteParams = () => ({}), entityIdentifier = "entityId", createEntityIdentifier = "create") => {
39
58
  const route = useRoute();
40
59
  const router = useRouter();
@@ -125,7 +144,8 @@ export const useUiClient = () => {
125
144
  isFormDisabled,
126
145
  queryChanged,
127
146
  useCrudRouting,
128
- useFormField
147
+ useFormField,
148
+ createSkeleton
129
149
  }
130
150
  };
131
151
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@antify/ui-module",
3
3
  "private": false,
4
- "version": "1.9.0",
4
+ "version": "1.9.1",
5
5
  "license": "MIT",
6
6
  "sideEffects": false,
7
7
  "type": "module",