@antify/ui-module 1.8.5 → 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.d.mts CHANGED
@@ -1,6 +1,12 @@
1
- import { NuxtModule } from 'nuxt/schema';
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+ export * from '../dist/runtime/types.js';
2
3
 
3
- type ModuleOptions = {};
4
- declare const module: NuxtModule<ModuleOptions>;
4
+ type ModuleOptions = {
5
+ tailwindcss?: {
6
+ content?: string[];
7
+ };
8
+ };
5
9
 
6
- export { module as default };
10
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
11
+
12
+ export { _default as default };
package/dist/module.d.ts CHANGED
@@ -1,6 +1,12 @@
1
- import { NuxtModule } from 'nuxt/schema';
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+ export * from '../dist/runtime/types.js';
2
3
 
3
- type ModuleOptions = {};
4
- declare const module: NuxtModule<ModuleOptions>;
4
+ type ModuleOptions = {
5
+ tailwindcss?: {
6
+ content?: string[];
7
+ };
8
+ };
5
9
 
6
- export { module as default };
10
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
11
+
12
+ export { _default as default };
package/dist/module.json CHANGED
@@ -1,5 +1,9 @@
1
1
  {
2
- "name": "ui-module",
2
+ "name": "@antify/ui-module",
3
3
  "configKey": "uiModule",
4
- "version": "1.8.5"
4
+ "version": "1.9.1",
5
+ "builder": {
6
+ "@nuxt/module-builder": "0.8.3",
7
+ "unbuild": "2.0.0"
8
+ }
5
9
  }
package/dist/module.mjs CHANGED
@@ -1,24 +1,6 @@
1
- import tailwindConfig from '@antify/ui/config';
1
+ import tailwindConfig from '../dist/runtime/tailwindConfig.js';
2
2
  import { defineNuxtModule, createResolver, addPlugin, addImportsDir, addComponent } from '@nuxt/kit';
3
-
4
- tailwindConfig.content = [
5
- // For module dev
6
- "./src/runtime/**/*.{vue,js,ts,jsx,tsx}",
7
- "./src/runtime/**/*.stories.ts",
8
- "./playground/app.vue",
9
- "./playground/components/**/*.{vue,js,ts,jsx,tsx}",
10
- "./playground/pages/**/*.{vue,js,ts,jsx,tsx}",
11
- "./playground/layouts/**/*.{vue,js,ts,jsx,tsx}",
12
- "../ui-module/src/**/*.{vue,js,ts,jsx,tsx}",
13
- // For project dev
14
- "./app.vue",
15
- "./components/**/*.{vue,js,ts,jsx,tsx}",
16
- "./pages/**/*.{vue,js,ts,jsx,tsx}",
17
- "./layouts/**/*.{vue,js,ts,jsx,tsx}",
18
- // If this config is used in a project
19
- "./node_modules/@antify/*/dist/**/*.{js,vue,ts}",
20
- "./node_modules/@antify/*/src/**/*.{js,vue,ts}"
21
- ];
3
+ import { defu } from 'defu';
22
4
 
23
5
  const uiComponents = [
24
6
  "AntActionButton",
@@ -91,7 +73,7 @@ const uiComponents = [
91
73
  const moduleKey = "uiModule";
92
74
  const module = defineNuxtModule({
93
75
  meta: {
94
- name: "ui-module",
76
+ name: "@antify/ui-module",
95
77
  configKey: moduleKey
96
78
  },
97
79
  defaults: {},
@@ -109,7 +91,7 @@ const module = defineNuxtModule({
109
91
  filePath: "@antify/ui/components"
110
92
  });
111
93
  });
112
- nuxt.options.postcss.plugins.tailwindcss = tailwindConfig;
94
+ nuxt.options.postcss.plugins.tailwindcss = defu(tailwindConfig, options.tailwindcss);
113
95
  nuxt.options.css.push(resolve(runtimeDir, "assets/tailwind.css"));
114
96
  nuxt.options.runtimeConfig.public[moduleKey] = options;
115
97
  }
@@ -2,11 +2,16 @@
2
2
  * Set of helper functions for client side
3
3
  */
4
4
  import type { FetchResponse, FetchError } from 'ofetch';
5
- import { type LocationQuery, type RouteLocationRaw } from '#vue-router';
5
+ import { type LocationQuery, type RouteLocationRaw, type LocationQueryRaw, type RouteParams } from '#vue-router';
6
6
  import { type Ref } from '#imports';
7
- export declare function handleNotFoundResponse(response: FetchResponse, fallbackUrl: RouteLocationRaw): Promise<void>;
8
- export declare function handleResponseError(error: Ref<FetchError | null>): void;
7
+ import { InputState } from '@antify/ui';
8
+ declare function handleNotFoundResponse(response: FetchResponse, fallbackUrl: RouteLocationRaw): Promise<void>;
9
+ declare function handleResponseError(error: Ref<FetchError | null>): void;
9
10
  declare function isFormDisabled(status: Ref | Ref[]): boolean;
11
+ /**
12
+ * Detect if the given queryToWatch changed.
13
+ */
14
+ declare function queryChanged(from: LocationQuery, to: LocationQuery, queryToWatch: string | string[]): boolean;
10
15
  /**
11
16
  * Creates a skeleton ref with flicker protection by prevent switching to fast from true to false.
12
17
  *
@@ -14,12 +19,33 @@ declare function isFormDisabled(status: Ref | Ref[]): boolean;
14
19
  * on initial loading.
15
20
  *
16
21
  * @param pending
22
+ * @deprecated - Flicker protection is implemented in @antify/ui directly. Do not handle it from outside anymore.
17
23
  */
18
24
  declare function createSkeleton(pending: Ref<boolean>): Ref<boolean>;
25
+ export type CrudRoutingOptions = {
26
+ detailRouteName: string;
27
+ listingRouteName: string;
28
+ getDetailRouteParams?: () => RouteParams;
29
+ getListingRouteParams?: () => RouteParams;
30
+ entityIdentifier?: string;
31
+ createEntityIdentifier?: string;
32
+ };
33
+ export type FormFieldType = {
34
+ errors: string[];
35
+ state: InputState;
36
+ validate: () => Promise<void>;
37
+ };
19
38
  /**
20
- * Detect if the given queryToWatch changed.
39
+ * Yup validation throws an error if the value expect not the given schema.
40
+ * This function creates a wrapper around it, to easily use it with antify ui components.
21
41
  */
22
- declare function queryChanged(from: LocationQuery, to: LocationQuery, queryToWatch: string | string[]): boolean;
42
+ export declare function useFormField(validationFn: () => Promise<void>): {
43
+ errors: never[];
44
+ state: InputState;
45
+ validate: () => Promise<void>;
46
+ };
47
+ type GroupedForm = Record<string, FormFieldType[]>;
48
+ export declare function useGroupedForm<T extends GroupedForm>(form: T): {};
23
49
  export declare const useUiClient: () => {
24
50
  handler: {
25
51
  handleNotFoundResponse: typeof handleNotFoundResponse;
@@ -27,8 +53,38 @@ export declare const useUiClient: () => {
27
53
  };
28
54
  utils: {
29
55
  isFormDisabled: typeof isFormDisabled;
30
- createSkeleton: typeof createSkeleton;
31
56
  queryChanged: typeof queryChanged;
57
+ useCrudRouting: (detailRouteName: string, listingRouteName: string, getDetailRouteParams?: () => RouteParams, getListingRouteParams?: () => RouteParams, entityIdentifier?: string, createEntityIdentifier?: string) => {
58
+ isListingPage: import("vue").ComputedRef<boolean>;
59
+ isDetailPage: import("vue").ComputedRef<boolean>;
60
+ isUpdatePage: import("vue").ComputedRef<boolean>;
61
+ isCreatePage: import("vue").ComputedRef<boolean>;
62
+ getDetailRoute(entityId: string | string[], query?: LocationQueryRaw): {
63
+ name: string;
64
+ params: {
65
+ [x: string]: string | string[] | string[];
66
+ };
67
+ query: LocationQueryRaw;
68
+ };
69
+ getDetailSubRoute(entityId: string | string[], subRouteNameExtension: string, query?: LocationQueryRaw): {
70
+ name: string;
71
+ params: {
72
+ [x: string]: string | string[] | string[];
73
+ };
74
+ query: LocationQueryRaw;
75
+ };
76
+ getListingRoute(query?: LocationQueryRaw): {
77
+ name: string;
78
+ params: import("vue-router").RouteParamsGeneric;
79
+ query: LocationQueryRaw;
80
+ };
81
+ getEntityId(): string | string[];
82
+ goToListingPage(query?: LocationQueryRaw): Promise<void | import("vue-router").NavigationFailure | undefined>;
83
+ goToDetailPage(entityId?: string | string[], query?: LocationQuery): Promise<void | import("vue-router").NavigationFailure | undefined>;
84
+ goToDetailSubPage(subRouteNameExtension: string, query?: LocationQueryRaw): Promise<void | import("vue-router").NavigationFailure | undefined>;
85
+ };
86
+ useFormField: typeof useFormField;
87
+ createSkeleton: typeof createSkeleton;
32
88
  };
33
89
  };
34
90
  export {};
@@ -0,0 +1,151 @@
1
+ import {
2
+ useNuxtApp,
3
+ navigateTo,
4
+ createError,
5
+ useRouter,
6
+ useRoute,
7
+ computed,
8
+ reactive,
9
+ ref
10
+ } from "#imports";
11
+ import { InputState } from "@antify/ui";
12
+ import { watchOnce } from "@vueuse/core";
13
+ async function handleNotFoundResponse(response, fallbackUrl) {
14
+ if (response._data?.notFound) {
15
+ useNuxtApp().$uiModule.toaster.toastError("Entity not found. Maybe an other user deleted it.");
16
+ await navigateTo(fallbackUrl);
17
+ }
18
+ }
19
+ function handleResponseError(error) {
20
+ if (error.value) {
21
+ throw createError({ ...error.value?.data, statusCode: 500, fatal: true });
22
+ }
23
+ }
24
+ function isFormDisabled(status) {
25
+ if (Array.isArray(status)) {
26
+ return status.some((status2) => isFormDisabled(status2));
27
+ }
28
+ return status.value === "pending";
29
+ }
30
+ function queryChanged(from, to, queryToWatch) {
31
+ const _queryToWatch = Array.isArray(queryToWatch) ? queryToWatch : [queryToWatch];
32
+ const changes = Object.keys(to).reduce((acc, key) => {
33
+ if (to[key] !== from[key]) {
34
+ acc[key] = to[key];
35
+ }
36
+ return acc;
37
+ }, {});
38
+ return _queryToWatch.some((key) => changes[key] !== void 0);
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
+ }
57
+ const useCrudRouting = (detailRouteName, listingRouteName, getDetailRouteParams = () => ({}), getListingRouteParams = () => ({}), entityIdentifier = "entityId", createEntityIdentifier = "create") => {
58
+ const route = useRoute();
59
+ const router = useRouter();
60
+ const isDetailPage = computed(() => {
61
+ return route.name?.includes(detailRouteName || "") || false;
62
+ });
63
+ return {
64
+ isListingPage: computed(() => route.name === listingRouteName),
65
+ isDetailPage,
66
+ isUpdatePage: computed(() => isDetailPage.value && route.params[entityIdentifier] !== createEntityIdentifier),
67
+ isCreatePage: computed(() => isDetailPage.value && route.params[entityIdentifier] === createEntityIdentifier),
68
+ getDetailRoute(entityId, query = route.query) {
69
+ return {
70
+ name: detailRouteName,
71
+ params: {
72
+ ...getDetailRouteParams(),
73
+ [entityIdentifier]: entityId
74
+ },
75
+ query
76
+ };
77
+ },
78
+ getDetailSubRoute(entityId, subRouteNameExtension, query = route.query) {
79
+ return {
80
+ name: `${detailRouteName}-${subRouteNameExtension}`,
81
+ params: {
82
+ ...getDetailRouteParams(),
83
+ [entityIdentifier]: entityId
84
+ },
85
+ query
86
+ };
87
+ },
88
+ getListingRoute(query = route.query) {
89
+ return {
90
+ name: listingRouteName,
91
+ params: getListingRouteParams(),
92
+ query
93
+ };
94
+ },
95
+ getEntityId() {
96
+ const entityId = route.params[entityIdentifier];
97
+ if (entityId === void 0) {
98
+ throw new Error(`Entity identifier "${entityIdentifier}" is not set in route.params. Make sure you set it in route and this function is called on a detail page.`);
99
+ }
100
+ return entityId;
101
+ },
102
+ // TODO:: use the given query and merge it into route.query
103
+ goToListingPage(query = route.query) {
104
+ return router.push(this.getListingRoute(query));
105
+ },
106
+ goToDetailPage(entityId = "create", query = route.query) {
107
+ return router.push(this.getDetailRoute(entityId, query));
108
+ },
109
+ goToDetailSubPage(subRouteNameExtension, query = route.query) {
110
+ return router.push(this.getDetailSubRoute(subRouteNameExtension, query));
111
+ }
112
+ };
113
+ };
114
+ export function useFormField(validationFn) {
115
+ const _reactive = reactive({
116
+ errors: [],
117
+ state: InputState.base,
118
+ async validate() {
119
+ try {
120
+ await validationFn();
121
+ _reactive.errors = [];
122
+ _reactive.state = InputState.base;
123
+ } catch (e) {
124
+ if (e?.name !== "ValidationError") {
125
+ throw e;
126
+ }
127
+ _reactive.errors = e?.errors || [];
128
+ _reactive.state = InputState.danger;
129
+ }
130
+ }
131
+ });
132
+ return _reactive;
133
+ }
134
+ export function useGroupedForm(form) {
135
+ return {};
136
+ }
137
+ export const useUiClient = () => {
138
+ return {
139
+ handler: {
140
+ handleNotFoundResponse,
141
+ handleResponseError
142
+ },
143
+ utils: {
144
+ isFormDisabled,
145
+ queryChanged,
146
+ useCrudRouting,
147
+ useFormField,
148
+ createSkeleton
149
+ }
150
+ };
151
+ };
@@ -1,2 +1,46 @@
1
- declare const _default: any;
1
+ declare const _default: import("nuxt/app").Plugin<{
2
+ uiModule: {
3
+ toaster: {
4
+ getToasts(): {
5
+ id?: string | undefined;
6
+ title: string;
7
+ content?: string | undefined;
8
+ type: import("@antify/ui").InputState;
9
+ hasIcon?: boolean | undefined;
10
+ }[];
11
+ toast(toast: import("@antify/ui").Toast): void;
12
+ removeToast(toast: import("@antify/ui").Toast): void;
13
+ toastSuccess(message: string): void;
14
+ toastError(message: string): void;
15
+ toastWarning(message: string): void;
16
+ toastInfo(message: string): void;
17
+ toastDeleted(): void;
18
+ toastCreated(): void;
19
+ toastUpdated(): void;
20
+ toastDuplicated(): void;
21
+ };
22
+ };
23
+ }> & import("nuxt/app").ObjectPlugin<{
24
+ uiModule: {
25
+ toaster: {
26
+ getToasts(): {
27
+ id?: string | undefined;
28
+ title: string;
29
+ content?: string | undefined;
30
+ type: import("@antify/ui").InputState;
31
+ hasIcon?: boolean | undefined;
32
+ }[];
33
+ toast(toast: import("@antify/ui").Toast): void;
34
+ removeToast(toast: import("@antify/ui").Toast): void;
35
+ toastSuccess(message: string): void;
36
+ toastError(message: string): void;
37
+ toastWarning(message: string): void;
38
+ toastInfo(message: string): void;
39
+ toastDeleted(): void;
40
+ toastCreated(): void;
41
+ toastUpdated(): void;
42
+ toastDuplicated(): void;
43
+ };
44
+ };
45
+ }>;
2
46
  export default _default;
@@ -7,14 +7,14 @@ tailwindConfig.content = [
7
7
  "./playground/components/**/*.{vue,js,ts,jsx,tsx}",
8
8
  "./playground/pages/**/*.{vue,js,ts,jsx,tsx}",
9
9
  "./playground/layouts/**/*.{vue,js,ts,jsx,tsx}",
10
- "../ui-module/src/**/*.{vue,js,ts,jsx,tsx}",
10
+ // '../ui-module/src/**/*.{vue,js,ts,jsx,tsx}',
11
11
  // For project dev
12
12
  "./app.vue",
13
13
  "./components/**/*.{vue,js,ts,jsx,tsx}",
14
14
  "./pages/**/*.{vue,js,ts,jsx,tsx}",
15
15
  "./layouts/**/*.{vue,js,ts,jsx,tsx}",
16
16
  // If this config is used in a project
17
- "./node_modules/@antify/*/dist/**/*.{js,vue,ts}",
18
- "./node_modules/@antify/*/src/**/*.{js,vue,ts}"
17
+ "./node_modules/@antify/*/dist/**/*.{js,vue,ts}"
18
+ // './node_modules/@antify/*/src/**/*.{js,vue,ts}',
19
19
  ];
20
20
  export default tailwindConfig;
@@ -0,0 +1 @@
1
+ export { type CrudRoutingOptions, type FormFieldType } from './composables/useUiClient.js';
File without changes
package/dist/types.d.mts CHANGED
@@ -1,8 +1,7 @@
1
+ import type { NuxtModule } from '@nuxt/schema'
1
2
 
2
- import type { } from './module.js'
3
+ import type { default as Module } from './module.js'
3
4
 
5
+ export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
4
6
 
5
-
6
-
7
-
8
- export type { default } from './module.js'
7
+ export { default } from './module.js'
package/dist/types.d.ts CHANGED
@@ -1,8 +1,7 @@
1
+ import type { NuxtModule } from '@nuxt/schema'
1
2
 
2
- import type { } from './module'
3
+ import type { default as Module } from './module'
3
4
 
5
+ export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
4
6
 
5
-
6
-
7
-
8
- export type { default } from './module'
7
+ export { default } from './module'
package/package.json CHANGED
@@ -1,25 +1,26 @@
1
1
  {
2
2
  "name": "@antify/ui-module",
3
3
  "private": false,
4
- "version": "1.8.5",
4
+ "version": "1.9.1",
5
5
  "license": "MIT",
6
+ "sideEffects": false,
6
7
  "type": "module",
7
8
  "exports": {
8
9
  ".": {
10
+ "types": "./dist/module.d.ts",
9
11
  "import": "./dist/module.mjs",
10
- "require": "./dist/module.cjs",
11
- "types": "./dist/types.d.ts"
12
+ "require": "./dist/module.cjs"
12
13
  }
13
14
  },
15
+ "main": "./dist/module.mjs",
16
+ "types": "./dist/module.d.ts",
14
17
  "files": [
15
18
  "dist"
16
19
  ],
17
- "main": "./dist/module.cjs",
18
- "types": "./dist/types.d.ts",
19
20
  "dependencies": {
20
21
  "@antify/ui": "^1.0.4",
21
22
  "@fortawesome/vue-fontawesome": "^3.0.8",
22
- "@nuxt/kit": "^3.9.3",
23
+ "@nuxt/kit": "^3.13.1",
23
24
  "@vueuse/core": "^10.7.2",
24
25
  "tailwindcss": "^3.4.10",
25
26
  "vue": "^3.4.29"
@@ -27,23 +28,25 @@
27
28
  "devDependencies": {
28
29
  "@faker-js/faker": "^8.3.1",
29
30
  "@fortawesome/free-solid-svg-icons": "^6.6.0",
30
- "@nuxt/eslint-config": "latest",
31
+ "@nuxt/eslint-config": "^0.4.0",
31
32
  "@nuxt/module-builder": "latest",
32
33
  "autoprefixer": "^10.4.16",
33
34
  "defu": "^6.1.4",
34
- "eslint": "latest",
35
- "eslint-plugin-storybook": "latest",
36
- "nuxt": "^3.9.3",
35
+ "eslint": "^8.0.0",
36
+ "eslint-plugin-storybook": "^0.8.0",
37
+ "nuxt": "^3.13.1",
37
38
  "ofetch": "^1.3.3",
38
39
  "standard-version": "latest",
39
- "typescript": "^5.3.3",
40
- "unbuild": "^2.0.0"
40
+ "typescript": "^5.5.4"
41
+ },
42
+ "resolutions": {
43
+ "@antify/ui-module": "workspace:*"
41
44
  },
42
45
  "scripts": {
43
- "build": "nuxt-module-build",
46
+ "build": "nuxt-module-build build",
44
47
  "dev": "nuxi dev playground",
45
48
  "dev:build": "nuxi build playground",
46
- "dev:prepare": "nuxt-module-build build && nuxi prepare playground",
49
+ "dev:prepare": "nuxi prepare playground",
47
50
  "release": "standard-version && git push --follow-tags && pnpm publish --access public"
48
51
  }
49
52
  }
@@ -1,60 +0,0 @@
1
- import { useNuxtApp, navigateTo, createError, ref } from "#imports";
2
- import { watchOnce } from "@vueuse/core";
3
- export async function handleNotFoundResponse(response, fallbackUrl) {
4
- if (response._data?.notFound) {
5
- useNuxtApp().$uiModule.toaster.toastError("Entity not found. Maybe an other user deleted it.");
6
- await navigateTo(fallbackUrl);
7
- }
8
- }
9
- export function handleResponseError(error) {
10
- if (error.value) {
11
- throw createError({ ...error.value?.data, statusCode: 500, fatal: true });
12
- }
13
- }
14
- function isFormDisabled(status) {
15
- if (Array.isArray(status)) {
16
- return status.some((status2) => isFormDisabled(status2));
17
- }
18
- return status.value === "pending";
19
- }
20
- function createSkeleton(pending) {
21
- const skeleton = ref(true);
22
- const initialTimestamp = Date.now();
23
- const minShowTime = 500;
24
- watchOnce(pending, () => {
25
- const timeShowed = Date.now() - (initialTimestamp || Date.now());
26
- const restTimeToShow = minShowTime - timeShowed > 0 ? minShowTime - timeShowed : 0;
27
- if (restTimeToShow === 0) {
28
- skeleton.value = false;
29
- } else {
30
- setTimeout(() => {
31
- skeleton.value = false;
32
- }, restTimeToShow);
33
- }
34
- });
35
- return skeleton;
36
- }
37
- function queryChanged(from, to, queryToWatch) {
38
- const _queryToWatch = Array.isArray(queryToWatch) ? queryToWatch : [queryToWatch];
39
- const changes = Object.keys(to).reduce((acc, key) => {
40
- if (to[key] !== from[key]) {
41
- acc[key] = to[key];
42
- }
43
- return acc;
44
- }, {});
45
- return _queryToWatch.some((key) => changes[key] !== void 0);
46
- }
47
- export const useUiClient = () => {
48
- return {
49
- handler: {
50
- handleNotFoundResponse,
51
- handleResponseError
52
- },
53
- utils: {
54
- isFormDisabled,
55
- createSkeleton,
56
- queryChanged
57
- // createFlickerProtectRef
58
- }
59
- };
60
- };