@effect-app/vue-components 0.0.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/README.md +184 -0
- package/dist/types/components/OmegaForm/OmegaErrors.vue.d.ts +2 -0
- package/dist/types/components/OmegaForm/OmegaErrorsContext.d.ts +35 -0
- package/dist/types/components/OmegaForm/OmegaFormStuff.d.ts +85 -0
- package/dist/types/components/OmegaForm/OmegaInput.vue.d.ts +38 -0
- package/dist/types/components/OmegaForm/OmegaInternalInput.vue.d.ts +25 -0
- package/dist/types/components/OmegaForm/OmegaWrapper.vue.d.ts +43 -0
- package/dist/types/components/OmegaForm/getOmegaStore.d.ts +3 -0
- package/dist/types/components/OmegaForm/index.d.ts +52 -0
- package/dist/types/components/OmegaForm/useOmegaForm.d.ts +6 -0
- package/dist/types/components/TestComponent.vue.d.ts +6 -0
- package/dist/types/components/index.d.ts +3 -0
- package/dist/types/constants/index.d.ts +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/utils/index.d.ts +7 -0
- package/dist/vue-components.css +1 -0
- package/dist/vue-components.es.js +624 -0
- package/package.json +48 -0
- package/src/assets/.keep +0 -0
- package/src/components/OmegaForm/OmegaErrors.vue +143 -0
- package/src/components/OmegaForm/OmegaErrorsContext.ts +64 -0
- package/src/components/OmegaForm/OmegaFormStuff.ts +575 -0
- package/src/components/OmegaForm/OmegaInput.vue +91 -0
- package/src/components/OmegaForm/OmegaInternalInput.vue +216 -0
- package/src/components/OmegaForm/OmegaWrapper.vue +137 -0
- package/src/components/OmegaForm/getOmegaStore.ts +32 -0
- package/src/components/OmegaForm/index.ts +29 -0
- package/src/components/OmegaForm/useOmegaForm.ts +61 -0
- package/src/components/TestComponent.vue +15 -0
- package/src/components/index.ts +6 -0
- package/src/components/style.css +3 -0
- package/src/constants/index.ts +1 -0
- package/src/env.d.ts +8 -0
- package/src/index.ts +17 -0
- package/src/utils/index.ts +12 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<Transition>
|
|
3
|
+
<div v-if="
|
|
4
|
+
formSubmissionAttempts > 0 &&
|
|
5
|
+
(errors.length || showedGeneralErrors.length)
|
|
6
|
+
" class="error-alert">
|
|
7
|
+
<v-alert type="error" variant="tonal" role="alert" aria-live="polite" class="mb-4">
|
|
8
|
+
<div class="text-h6 mb-3">{{ trans("form.includes_error") }}:</div>
|
|
9
|
+
<component :is="errors.length > 1 ? 'ul' : 'div'" v-if="errors.length" class="error-list">
|
|
10
|
+
<component :is="errors.length > 1 ? 'li' : 'div'" v-for="error in errors" :key="error.inputId"
|
|
11
|
+
class="error-item">
|
|
12
|
+
<div class="font-weight-medium">{{ error.label }}</div>
|
|
13
|
+
<div class="error-message">
|
|
14
|
+
<component :is="error.errors.length > 1 ? 'ul' : 'div'" class="error-list">
|
|
15
|
+
<component :is="error.errors.length > 1 ? 'li' : 'span'" v-for="e in error.errors" :key="e">
|
|
16
|
+
{{ e }}
|
|
17
|
+
</component>
|
|
18
|
+
</component>
|
|
19
|
+
</div>
|
|
20
|
+
<a :href="`#${error.inputId}`" class="error-link">
|
|
21
|
+
<v-icon :icon="mdiLink" />
|
|
22
|
+
{{ trans("form.fix_input") }}
|
|
23
|
+
</a>
|
|
24
|
+
</component>
|
|
25
|
+
</component>
|
|
26
|
+
<span v-else>
|
|
27
|
+
{{ showedGeneralErrors[0] }}
|
|
28
|
+
</span>
|
|
29
|
+
</v-alert>
|
|
30
|
+
</div>
|
|
31
|
+
</Transition>
|
|
32
|
+
</template>
|
|
33
|
+
|
|
34
|
+
<script setup lang="ts">
|
|
35
|
+
import { useOmegaErrors } from "./OmegaErrorsContext"
|
|
36
|
+
import { mdiLink } from "@mdi/js"
|
|
37
|
+
import { useIntl } from "../../utils"
|
|
38
|
+
import type { StandardSchemaV1Issue } from "@tanstack/vue-form"
|
|
39
|
+
import { computed } from "vue"
|
|
40
|
+
|
|
41
|
+
const { errors, formSubmissionAttempts, generalErrors } = useOmegaErrors()
|
|
42
|
+
|
|
43
|
+
const { trans } = useIntl()
|
|
44
|
+
|
|
45
|
+
const showedGeneralErrors = computed(() => {
|
|
46
|
+
if (!generalErrors.value) return []
|
|
47
|
+
|
|
48
|
+
return generalErrors.value
|
|
49
|
+
.filter((record): record is Record<string, StandardSchemaV1Issue[]> =>
|
|
50
|
+
Boolean(record),
|
|
51
|
+
)
|
|
52
|
+
.flatMap(errorRecord =>
|
|
53
|
+
Object.values(errorRecord)
|
|
54
|
+
.filter((issues): issues is StandardSchemaV1Issue[] => Boolean(issues))
|
|
55
|
+
.flatMap(issues =>
|
|
56
|
+
issues
|
|
57
|
+
.filter(
|
|
58
|
+
(issue): issue is StandardSchemaV1Issue & { message: string } =>
|
|
59
|
+
Boolean(issue?.message),
|
|
60
|
+
)
|
|
61
|
+
.map(issue => issue.message),
|
|
62
|
+
),
|
|
63
|
+
)
|
|
64
|
+
})
|
|
65
|
+
</script>
|
|
66
|
+
|
|
67
|
+
<style scoped>
|
|
68
|
+
.v-enter-from,
|
|
69
|
+
.v-leave-to {
|
|
70
|
+
max-height: 0px;
|
|
71
|
+
grid-template-rows: 0fr;
|
|
72
|
+
opacity: 0;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.v-enter-active,
|
|
76
|
+
.v-leave-active {
|
|
77
|
+
display: grid;
|
|
78
|
+
transition: all 0.15s;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.v-enter-to,
|
|
82
|
+
.v-leave-from {
|
|
83
|
+
grid-template-rows: 1fr;
|
|
84
|
+
max-height: 50vh;
|
|
85
|
+
opacity: 1;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.error-alert {
|
|
89
|
+
transition-behavior: allow-discrete;
|
|
90
|
+
display: grid;
|
|
91
|
+
overflow: hidden;
|
|
92
|
+
min-height: 0;
|
|
93
|
+
|
|
94
|
+
>* {
|
|
95
|
+
min-height: 0;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.error-list {
|
|
100
|
+
container-type: inline-size;
|
|
101
|
+
display: grid;
|
|
102
|
+
grid-template-columns: auto 1fr auto;
|
|
103
|
+
gap: 8px;
|
|
104
|
+
align-items: start;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@container (max-width: 28.125rem) {
|
|
108
|
+
.error-list {
|
|
109
|
+
grid-template-columns: auto 1fr;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.error-link {
|
|
113
|
+
grid-column: 1 / -1;
|
|
114
|
+
justify-self: end;
|
|
115
|
+
padding-bottom: 16px;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@container (max-width: 18.75rem) {
|
|
120
|
+
.error-list {
|
|
121
|
+
grid-template-columns: 1fr;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.error-message {
|
|
125
|
+
grid-column: 1 / -1;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.error-item {
|
|
130
|
+
display: contents;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
a {
|
|
134
|
+
min-width: min-content;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.error-link {
|
|
138
|
+
color: inherit;
|
|
139
|
+
text-decoration: none;
|
|
140
|
+
display: inline-flex;
|
|
141
|
+
align-items: center;
|
|
142
|
+
}
|
|
143
|
+
</style>
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type InjectionKey,
|
|
3
|
+
provide,
|
|
4
|
+
inject,
|
|
5
|
+
ref,
|
|
6
|
+
readonly,
|
|
7
|
+
type Ref,
|
|
8
|
+
} from "vue"
|
|
9
|
+
import type { OmegaError } from "./OmegaFormStuff"
|
|
10
|
+
import type { StandardSchemaV1Issue } from "@tanstack/vue-form"
|
|
11
|
+
|
|
12
|
+
export const OmegaErrorsKey = Symbol() as InjectionKey<{
|
|
13
|
+
errors: Ref<readonly OmegaError[]>
|
|
14
|
+
addError: (error: OmegaError) => void
|
|
15
|
+
removeError: (inputId: string) => void
|
|
16
|
+
clearErrors: () => void
|
|
17
|
+
formSubmissionAttempts: Ref<number>
|
|
18
|
+
generalErrors: Ref<
|
|
19
|
+
(Record<string, StandardSchemaV1Issue[]> | undefined)[] | undefined
|
|
20
|
+
>
|
|
21
|
+
}>
|
|
22
|
+
|
|
23
|
+
export function provideOmegaErrors(
|
|
24
|
+
formSubmissionAttempts: Ref<number>,
|
|
25
|
+
generalErrors: Ref<
|
|
26
|
+
(Record<string, StandardSchemaV1Issue[]> | undefined)[] | undefined
|
|
27
|
+
>,
|
|
28
|
+
) {
|
|
29
|
+
const errors = ref<OmegaError[]>([])
|
|
30
|
+
|
|
31
|
+
const removeError = (inputId: string) => {
|
|
32
|
+
errors.value = errors.value.filter(error => error.inputId !== inputId)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const addError = (error: OmegaError) => {
|
|
36
|
+
removeError(error.inputId)
|
|
37
|
+
errors.value.push(error)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const clearErrors = () => {
|
|
41
|
+
errors.value = []
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const context = {
|
|
45
|
+
errors: readonly(errors),
|
|
46
|
+
addError,
|
|
47
|
+
removeError,
|
|
48
|
+
clearErrors,
|
|
49
|
+
formSubmissionAttempts,
|
|
50
|
+
generalErrors,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
provide(OmegaErrorsKey, context)
|
|
54
|
+
|
|
55
|
+
return context
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function useOmegaErrors() {
|
|
59
|
+
const context = inject(OmegaErrorsKey)
|
|
60
|
+
if (!context) {
|
|
61
|
+
throw new Error("useOmegaErrors must be used within an OmegaForm provider")
|
|
62
|
+
}
|
|
63
|
+
return context
|
|
64
|
+
}
|