@antify/template-module 0.0.2

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.
Files changed (64) hide show
  1. package/README.md +163 -0
  2. package/dist/module.d.mts +10 -0
  3. package/dist/module.d.ts +10 -0
  4. package/dist/module.json +9 -0
  5. package/dist/module.mjs +101 -0
  6. package/dist/runtime/assets/antify.css +1 -0
  7. package/dist/runtime/components/Main.mdx +6 -0
  8. package/dist/runtime/components/buttons/ActionButton.d.vue.ts +52 -0
  9. package/dist/runtime/components/buttons/ActionButton.vue +74 -0
  10. package/dist/runtime/components/buttons/ActionButton.vue.d.ts +52 -0
  11. package/dist/runtime/components/buttons/CreateButton.d.vue.ts +25 -0
  12. package/dist/runtime/components/buttons/CreateButton.vue +67 -0
  13. package/dist/runtime/components/buttons/CreateButton.vue.d.ts +25 -0
  14. package/dist/runtime/components/buttons/DeleteButton.d.vue.ts +25 -0
  15. package/dist/runtime/components/buttons/DeleteButton.vue +67 -0
  16. package/dist/runtime/components/buttons/DeleteButton.vue.d.ts +25 -0
  17. package/dist/runtime/components/buttons/DuplicateButton.d.vue.ts +25 -0
  18. package/dist/runtime/components/buttons/DuplicateButton.vue +67 -0
  19. package/dist/runtime/components/buttons/DuplicateButton.vue.d.ts +25 -0
  20. package/dist/runtime/components/buttons/EditButton.d.vue.ts +25 -0
  21. package/dist/runtime/components/buttons/EditButton.vue +67 -0
  22. package/dist/runtime/components/buttons/EditButton.vue.d.ts +25 -0
  23. package/dist/runtime/components/buttons/SaveAndNewButton.d.vue.ts +25 -0
  24. package/dist/runtime/components/buttons/SaveAndNewButton.vue +70 -0
  25. package/dist/runtime/components/buttons/SaveAndNewButton.vue.d.ts +25 -0
  26. package/dist/runtime/components/buttons/SaveButton.d.vue.ts +25 -0
  27. package/dist/runtime/components/buttons/SaveButton.vue +68 -0
  28. package/dist/runtime/components/buttons/SaveButton.vue.d.ts +25 -0
  29. package/dist/runtime/components/crud/Crud.d.vue.ts +24 -0
  30. package/dist/runtime/components/crud/Crud.vue +43 -0
  31. package/dist/runtime/components/crud/Crud.vue.d.ts +24 -0
  32. package/dist/runtime/components/crud/CrudDetail.d.vue.ts +17 -0
  33. package/dist/runtime/components/crud/CrudDetail.vue +14 -0
  34. package/dist/runtime/components/crud/CrudDetail.vue.d.ts +17 -0
  35. package/dist/runtime/components/crud/CrudDetailActions.d.vue.ts +40 -0
  36. package/dist/runtime/components/crud/CrudDetailActions.vue +72 -0
  37. package/dist/runtime/components/crud/CrudDetailActions.vue.d.ts +40 -0
  38. package/dist/runtime/components/crud/CrudDetailNav.d.vue.ts +40 -0
  39. package/dist/runtime/components/crud/CrudDetailNav.vue +65 -0
  40. package/dist/runtime/components/crud/CrudDetailNav.vue.d.ts +40 -0
  41. package/dist/runtime/components/crud/CrudTableFilter.d.vue.ts +48 -0
  42. package/dist/runtime/components/crud/CrudTableFilter.vue +153 -0
  43. package/dist/runtime/components/crud/CrudTableFilter.vue.d.ts +48 -0
  44. package/dist/runtime/components/crud/CrudTableNav.d.vue.ts +23 -0
  45. package/dist/runtime/components/crud/CrudTableNav.vue +121 -0
  46. package/dist/runtime/components/crud/CrudTableNav.vue.d.ts +23 -0
  47. package/dist/runtime/components/dialogs/DeleteDialog.d.vue.ts +15 -0
  48. package/dist/runtime/components/dialogs/DeleteDialog.vue +64 -0
  49. package/dist/runtime/components/dialogs/DeleteDialog.vue.d.ts +15 -0
  50. package/dist/runtime/components/index.d.ts +15 -0
  51. package/dist/runtime/components/index.js +30 -0
  52. package/dist/runtime/composables/useUiClient.d.ts +90 -0
  53. package/dist/runtime/composables/useUiClient.js +151 -0
  54. package/dist/runtime/index.css +1 -0
  55. package/dist/runtime/index.d.ts +2 -0
  56. package/dist/runtime/index.js +2 -0
  57. package/dist/runtime/plugins/template-module.d.ts +48 -0
  58. package/dist/runtime/plugins/template-module.js +14 -0
  59. package/dist/runtime/types.d.ts +1 -0
  60. package/dist/runtime/types.js +0 -0
  61. package/dist/runtime/utils.d.ts +15 -0
  62. package/dist/runtime/utils.js +22 -0
  63. package/dist/types.d.mts +9 -0
  64. package/package.json +60 -0
@@ -0,0 +1,121 @@
1
+ <script setup>
2
+ import {
3
+ useRouter,
4
+ useRoute
5
+ } from "vue-router";
6
+ import {
7
+ computed,
8
+ ref,
9
+ watch
10
+ } from "vue";
11
+ import {
12
+ AntItemsPerPage,
13
+ AntPagination
14
+ } from "@antify/ui";
15
+ const emit = defineEmits([
16
+ "changeItemsPerPage",
17
+ "changePage"
18
+ ]);
19
+ const props = defineProps({
20
+ count: { type: [Number, null], required: true },
21
+ pageQuery: { type: String, required: false, default: "p" },
22
+ itemsPerPageQuery: { type: String, required: false, default: "ipp" },
23
+ fullWidth: { type: Boolean, required: false, default: true },
24
+ validItemsPerPage: { type: Array, required: false, default: () => [
25
+ 20,
26
+ 50,
27
+ 100,
28
+ 200
29
+ ] },
30
+ skeleton: { type: Boolean, required: false, default: false }
31
+ });
32
+ const route = useRoute();
33
+ const router = useRouter();
34
+ const itemsPerPageOptions = computed(() => props.validItemsPerPage);
35
+ const page = ref(1);
36
+ const itemsPerPage = computed({
37
+ get() {
38
+ return route.query[props.itemsPerPageQuery] ? Number.parseInt(route.query[props.itemsPerPageQuery]) : props.validItemsPerPage[0];
39
+ },
40
+ set(val) {
41
+ const query = {
42
+ ...route.query
43
+ };
44
+ query[props.itemsPerPageQuery] = `${val}`;
45
+ delete query[props.pageQuery];
46
+ page.value = 1;
47
+ (async () => {
48
+ await router.push({
49
+ ...route,
50
+ query
51
+ });
52
+ emit("changeItemsPerPage", val);
53
+ })();
54
+ }
55
+ });
56
+ const pages = computed(() => Math.ceil(props.count / itemsPerPage.value) || 1);
57
+ const _fullWidth = ref(props.fullWidth);
58
+ const onChangePage = (val) => {
59
+ const query = {
60
+ ...route.query
61
+ };
62
+ query[props.pageQuery] = `${val}`;
63
+ (async () => {
64
+ await router.push({
65
+ ...route,
66
+ query
67
+ });
68
+ emit("changePage", val);
69
+ })();
70
+ };
71
+ watch(() => props.fullWidth, (val) => {
72
+ setTimeout(() => {
73
+ _fullWidth.value = val;
74
+ }, val ? 300 : 200);
75
+ });
76
+ watch(() => route.query, () => {
77
+ if (route.query[props.pageQuery]) {
78
+ const _page = route.query[props.pageQuery] >= 1 ? Number.parseInt(route.query[props.pageQuery]) : 1;
79
+ if (_page <= 0 || _page > pages.value) {
80
+ return 1;
81
+ }
82
+ page.value = _page;
83
+ }
84
+ }, {
85
+ deep: true
86
+ });
87
+ </script>
88
+
89
+ <template>
90
+ <div
91
+ class="w-full"
92
+ data-e2e="crud-table-nav"
93
+ >
94
+ <div
95
+ class="flex w-full items-center p-2"
96
+ :class="{ 'justify-end': !_fullWidth, 'justify-between': _fullWidth }"
97
+ >
98
+ <div
99
+ v-if="_fullWidth"
100
+ class="flex gap-2 items-center text-for-white-bg-font text-sm"
101
+ data-e2e="items-per-page"
102
+ >
103
+ <AntItemsPerPage
104
+ v-model="itemsPerPage"
105
+ :items-per-page-options="itemsPerPageOptions"
106
+ :amount-of-items="count"
107
+ :selected-page="page"
108
+ :skeleton="skeleton"
109
+ />
110
+ </div>
111
+
112
+ <AntPagination
113
+ v-model="page"
114
+ :pages="pages"
115
+ :skeleton="skeleton"
116
+ :light-version="!_fullWidth"
117
+ @update:model-value="(val) => onChangePage(val)"
118
+ />
119
+ </div>
120
+ </div>
121
+ </template>
@@ -0,0 +1,23 @@
1
+ type __VLS_Props = {
2
+ count: number | null;
3
+ pageQuery?: string;
4
+ itemsPerPageQuery?: string;
5
+ fullWidth?: boolean;
6
+ validItemsPerPage?: number[];
7
+ skeleton?: boolean;
8
+ };
9
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
10
+ changeItemsPerPage: (...args: any[]) => void;
11
+ changePage: (...args: any[]) => void;
12
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
13
+ onChangeItemsPerPage?: ((...args: any[]) => any) | undefined;
14
+ onChangePage?: ((...args: any[]) => any) | undefined;
15
+ }>, {
16
+ skeleton: boolean;
17
+ fullWidth: boolean;
18
+ pageQuery: string;
19
+ itemsPerPageQuery: string;
20
+ validItemsPerPage: number[];
21
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
22
+ declare const _default: typeof __VLS_export;
23
+ export default _default;
@@ -0,0 +1,15 @@
1
+ type __VLS_Props = {
2
+ open: boolean;
3
+ entity: string;
4
+ };
5
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
6
+ close: (...args: any[]) => void;
7
+ "update:open": (...args: any[]) => void;
8
+ confirm: (...args: any[]) => void;
9
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
10
+ onClose?: ((...args: any[]) => any) | undefined;
11
+ "onUpdate:open"?: ((...args: any[]) => any) | undefined;
12
+ onConfirm?: ((...args: any[]) => any) | undefined;
13
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
14
+ declare const _default: typeof __VLS_export;
15
+ export default _default;
@@ -0,0 +1,64 @@
1
+ <script setup>
2
+ import {
3
+ AntDialog,
4
+ InputState,
5
+ AntButton,
6
+ State
7
+ } from "@antify/ui";
8
+ import DeleteButton from "../buttons/DeleteButton.vue";
9
+ import {
10
+ useVModel
11
+ } from "@vueuse/core";
12
+ const emit = defineEmits([
13
+ "update:open",
14
+ "close",
15
+ "confirm"
16
+ ]);
17
+ const props = defineProps({
18
+ open: { type: Boolean, required: true },
19
+ entity: { type: String, required: true }
20
+ });
21
+ const _open = useVModel(props, "open", emit);
22
+ function closeDialog() {
23
+ emit("update:open", false);
24
+ emit("close");
25
+ }
26
+ function confirmDialog() {
27
+ emit("update:open", false);
28
+ emit("confirm");
29
+ }
30
+ </script>
31
+
32
+ <template>
33
+ <AntDialog
34
+ v-model:open="_open"
35
+ :state="InputState.danger"
36
+ title="Löschen"
37
+ data-e2e="delete-dialog"
38
+ @close="() => $emit('close')"
39
+ >
40
+ <div>
41
+ Möchtest du wirklich <span class="font-semibold">{{ entity }}</span> löschen?
42
+ </div>
43
+
44
+ <template #footer>
45
+ <div
46
+ class="bg-base-100 gap-2 text-for-white-bg-font flex w-full justify-end"
47
+ >
48
+ <AntButton
49
+ :state="State.base"
50
+ @click="closeDialog"
51
+ >
52
+ Abbrechen
53
+ </AntButton>
54
+
55
+ <DeleteButton
56
+ filled
57
+ @click="confirmDialog"
58
+ >
59
+ Löschen
60
+ </DeleteButton>
61
+ </div>
62
+ </template>
63
+ </AntDialog>
64
+ </template>
@@ -0,0 +1,15 @@
1
+ type __VLS_Props = {
2
+ open: boolean;
3
+ entity: string;
4
+ };
5
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
6
+ close: (...args: any[]) => void;
7
+ "update:open": (...args: any[]) => void;
8
+ confirm: (...args: any[]) => void;
9
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
10
+ onClose?: ((...args: any[]) => any) | undefined;
11
+ "onUpdate:open"?: ((...args: any[]) => any) | undefined;
12
+ onConfirm?: ((...args: any[]) => any) | undefined;
13
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
14
+ declare const _default: typeof __VLS_export;
15
+ export default _default;
@@ -0,0 +1,15 @@
1
+ import ActionButton from './buttons/ActionButton.vue.js';
2
+ import CreateButton from './buttons/CreateButton.vue.js';
3
+ import DeleteButton from './buttons/DeleteButton.vue.js';
4
+ import DuplicateButton from './buttons/DuplicateButton.vue.js';
5
+ import EditButton from './buttons/EditButton.vue.js';
6
+ import SaveAndNewButton from './buttons/SaveAndNewButton.vue.js';
7
+ import SaveButton from './buttons/SaveButton.vue.js';
8
+ import DeleteDialog from './dialogs/DeleteDialog.vue.js';
9
+ import Crud from './crud/Crud.vue.js';
10
+ import CrudDetail from './crud/CrudDetail.vue.js';
11
+ import CrudDetailActions from './crud/CrudDetailActions.vue.js';
12
+ import CrudDetailNav from './crud/CrudDetailNav.vue.js';
13
+ import CrudTableFilter from './crud/CrudTableFilter.vue.js';
14
+ import CrudTableNav from './crud/CrudTableNav.vue.js';
15
+ export { ActionButton, CreateButton, DeleteButton, DuplicateButton, EditButton, SaveAndNewButton, SaveButton, DeleteDialog, Crud, CrudDetail, CrudDetailActions, CrudDetailNav, CrudTableFilter, CrudTableNav, };
@@ -0,0 +1,30 @@
1
+ import ActionButton from "./buttons/ActionButton.vue";
2
+ import CreateButton from "./buttons/CreateButton.vue";
3
+ import DeleteButton from "./buttons/DeleteButton.vue";
4
+ import DuplicateButton from "./buttons/DuplicateButton.vue";
5
+ import EditButton from "./buttons/EditButton.vue";
6
+ import SaveAndNewButton from "./buttons/SaveAndNewButton.vue";
7
+ import SaveButton from "./buttons/SaveButton.vue";
8
+ import DeleteDialog from "./dialogs/DeleteDialog.vue";
9
+ import Crud from "./crud/Crud.vue";
10
+ import CrudDetail from "./crud/CrudDetail.vue";
11
+ import CrudDetailActions from "./crud/CrudDetailActions.vue";
12
+ import CrudDetailNav from "./crud/CrudDetailNav.vue";
13
+ import CrudTableFilter from "./crud/CrudTableFilter.vue";
14
+ import CrudTableNav from "./crud/CrudTableNav.vue";
15
+ export {
16
+ ActionButton,
17
+ CreateButton,
18
+ DeleteButton,
19
+ DuplicateButton,
20
+ EditButton,
21
+ SaveAndNewButton,
22
+ SaveButton,
23
+ DeleteDialog,
24
+ Crud,
25
+ CrudDetail,
26
+ CrudDetailActions,
27
+ CrudDetailNav,
28
+ CrudTableFilter,
29
+ CrudTableNav
30
+ };
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Set of helper functions for client side
3
+ */
4
+ import type { FetchResponse, FetchError } from 'ofetch';
5
+ import { type LocationQuery, type RouteLocationRaw, type LocationQueryRaw, type RouteParams } from '#vue-router';
6
+ import { type Ref } from '#imports';
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;
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;
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>;
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
+ };
38
+ /**
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.
41
+ */
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): {};
49
+ export declare const useUiClient: () => {
50
+ handler: {
51
+ handleNotFoundResponse: typeof handleNotFoundResponse;
52
+ handleResponseError: typeof handleResponseError;
53
+ };
54
+ utils: {
55
+ isFormDisabled: typeof isFormDisabled;
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;
88
+ };
89
+ };
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().$templateModule.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
+ };
@@ -0,0 +1 @@
1
+ @import "@antify/ui";
@@ -0,0 +1,2 @@
1
+ export * from './components/index.js';
2
+ export * from './utils.js';
@@ -0,0 +1,2 @@
1
+ export * from "./components/index.js";
2
+ export * from "./utils.js";
@@ -0,0 +1,48 @@
1
+ declare const _default: import("nuxt/app").Plugin<{
2
+ templateModule: {
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
+ toastInvalidFormInfo(): void;
22
+ };
23
+ };
24
+ }> & import("nuxt/app").ObjectPlugin<{
25
+ templateModule: {
26
+ toaster: {
27
+ getToasts(): {
28
+ id?: string | undefined;
29
+ title: string;
30
+ content?: string | undefined;
31
+ type: import("@antify/ui").InputState;
32
+ hasIcon?: boolean | undefined;
33
+ }[];
34
+ toast(toast: import("@antify/ui").Toast): void;
35
+ removeToast(toast: import("@antify/ui").Toast): void;
36
+ toastSuccess(message: string): void;
37
+ toastError(message: string): void;
38
+ toastWarning(message: string): void;
39
+ toastInfo(message: string): void;
40
+ toastDeleted(): void;
41
+ toastCreated(): void;
42
+ toastUpdated(): void;
43
+ toastDuplicated(): void;
44
+ toastInvalidFormInfo(): void;
45
+ };
46
+ };
47
+ }>;
48
+ export default _default;
@@ -0,0 +1,14 @@
1
+ import { defineNuxtPlugin } from "#app";
2
+ import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
3
+ import { useToaster } from "@antify/ui";
4
+ export default defineNuxtPlugin((nuxtApp) => {
5
+ const toaster = useToaster();
6
+ nuxtApp.vueApp.component("FaIcon", FontAwesomeIcon);
7
+ return {
8
+ provide: {
9
+ templateModule: {
10
+ toaster
11
+ }
12
+ }
13
+ };
14
+ });
@@ -0,0 +1 @@
1
+ export { type CrudRoutingOptions, type FormFieldType, } from './composables/useUiClient.js';
File without changes
@@ -0,0 +1,15 @@
1
+ import { InputState } from "@antify/ui";
2
+ export type FormFieldType = {
3
+ errors: string[];
4
+ state: InputState;
5
+ validate: () => Promise<void>;
6
+ };
7
+ /**
8
+ * Yup validation throws an error if the value expect not the given schema.
9
+ * This function creates a wrapper around it, to easily use it with antify ui components.
10
+ */
11
+ export declare function useFormField(validationFn: () => Promise<void>): {
12
+ errors: never[];
13
+ state: InputState;
14
+ validate: () => Promise<void>;
15
+ };
@@ -0,0 +1,22 @@
1
+ import { reactive } from "vue";
2
+ import { InputState } from "@antify/ui";
3
+ export function useFormField(validationFn) {
4
+ const _reactive = reactive({
5
+ errors: [],
6
+ state: InputState.base,
7
+ async validate() {
8
+ try {
9
+ await validationFn();
10
+ _reactive.errors = [];
11
+ _reactive.state = InputState.base;
12
+ } catch (e) {
13
+ if (e?.name !== "ValidationError") {
14
+ throw e;
15
+ }
16
+ _reactive.errors = e?.errors || [];
17
+ _reactive.state = InputState.danger;
18
+ }
19
+ }
20
+ });
21
+ return _reactive;
22
+ }
@@ -0,0 +1,9 @@
1
+ import type { NuxtModule } from '@nuxt/schema'
2
+
3
+ import type { default as Module } from './module.mjs'
4
+
5
+ export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
6
+
7
+ export { default } from './module.mjs'
8
+
9
+ export * from '../dist/runtime/types.js'