srcdev-nuxt-forms 2.4.24 → 3.0.0

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 (86) hide show
  1. package/nuxt.config.ts +3 -0
  2. package/package.json +2 -2
  3. package/assets/styles/ally/_utils.css +0 -20
  4. package/assets/styles/ally/_variables.css +0 -8
  5. package/assets/styles/ally/index.css +0 -2
  6. package/assets/styles/forms/index.css +0 -2
  7. package/assets/styles/forms/themes/_error.css +0 -85
  8. package/assets/styles/forms/themes/_ghost.css +0 -85
  9. package/assets/styles/forms/themes/_input-action-underlined.css +0 -20
  10. package/assets/styles/forms/themes/_input-action.css +0 -20
  11. package/assets/styles/forms/themes/_primary.css +0 -92
  12. package/assets/styles/forms/themes/_secondary.css +0 -85
  13. package/assets/styles/forms/themes/_success.css +0 -85
  14. package/assets/styles/forms/themes/_tertiary.css +0 -85
  15. package/assets/styles/forms/themes/_warning.css +0 -85
  16. package/assets/styles/forms/themes/index.css +0 -9
  17. package/assets/styles/forms/variables/_sizes.css +0 -71
  18. package/assets/styles/forms/variables/_theme.css +0 -11
  19. package/assets/styles/forms/variables/index.css +0 -2
  20. package/assets/styles/main.css +0 -5
  21. package/assets/styles/typography/index.css +0 -2
  22. package/assets/styles/typography/utils/_font-classes.css +0 -190
  23. package/assets/styles/typography/utils/_weights.css +0 -69
  24. package/assets/styles/typography/utils/index.css +0 -2
  25. package/assets/styles/typography/variables/_colors.css +0 -14
  26. package/assets/styles/typography/variables/_reponsive-font-size.css +0 -10
  27. package/assets/styles/typography/variables/index.css +0 -2
  28. package/assets/styles/utils/_margin-helpers.css +0 -334
  29. package/assets/styles/utils/_padding-helpers.css +0 -308
  30. package/assets/styles/utils/_page.css +0 -36
  31. package/assets/styles/utils/index.css +0 -3
  32. package/assets/styles/variables/colors/_blue.css +0 -15
  33. package/assets/styles/variables/colors/_gray.css +0 -16
  34. package/assets/styles/variables/colors/_green.css +0 -15
  35. package/assets/styles/variables/colors/_orange.css +0 -15
  36. package/assets/styles/variables/colors/_red.css +0 -15
  37. package/assets/styles/variables/colors/_yellow.css +0 -15
  38. package/assets/styles/variables/colors/colors.css +0 -6
  39. package/assets/styles/variables/index.css +0 -1
  40. package/components/forms/c12/prop-validators/index.ts +0 -38
  41. package/components/forms/c12/utils.ts +0 -14
  42. package/components/forms/form-errors/InputError.vue +0 -172
  43. package/components/forms/form-errors/tests/InputError.spec.ts +0 -67
  44. package/components/forms/input-button/InputButtonCore.vue +0 -191
  45. package/components/forms/input-button/variants/InputButtonConfirm.vue +0 -66
  46. package/components/forms/input-button/variants/InputButtonSubmit.vue +0 -62
  47. package/components/forms/input-checkbox/MultipleCheckboxes.vue +0 -203
  48. package/components/forms/input-checkbox/SingleCheckbox.vue +0 -169
  49. package/components/forms/input-checkbox/tests/MultipleCheckboxes.spec.ts +0 -98
  50. package/components/forms/input-checkbox/tests/data/tags.json +0 -67
  51. package/components/forms/input-checkbox-radio/InputCheckboxRadioButton.vue +0 -214
  52. package/components/forms/input-checkbox-radio/InputCheckboxRadioCore.vue +0 -191
  53. package/components/forms/input-checkbox-radio/InputCheckboxRadioWithLabel.vue +0 -111
  54. package/components/forms/input-number/InputNumberCore.vue +0 -203
  55. package/components/forms/input-number/variants/InputNumberDefault.vue +0 -154
  56. package/components/forms/input-radio/MultipleRadiobuttons.vue +0 -201
  57. package/components/forms/input-radio/tests/MultipleRadioButtons.spec.ts +0 -89
  58. package/components/forms/input-radio/tests/data/tags.json +0 -67
  59. package/components/forms/input-range/InputRangeCore.vue +0 -274
  60. package/components/forms/input-range/variants/InputRangeDefault.vue +0 -156
  61. package/components/forms/input-range-fancy/InputRangeFancyCore.vue +0 -450
  62. package/components/forms/input-range-fancy/InputRangeFancyWithLabel.vue +0 -124
  63. package/components/forms/input-text/InputTextCore.vue +0 -331
  64. package/components/forms/input-text/variants/InputPasswordWithLabel.vue +0 -130
  65. package/components/forms/input-text/variants/InputTextAsNumberWithLabel.vue +0 -187
  66. package/components/forms/input-text/variants/InputTextWithLabel.vue +0 -298
  67. package/components/forms/input-textarea/InputTextareaCore.vue +0 -234
  68. package/components/forms/input-textarea/variants/InputTextareaWithLabel.vue +0 -267
  69. package/components/forms/toggle-switch/ToggleSwitchCore.vue +0 -198
  70. package/components/forms/toggle-switch/ToggleSwitchCoreOld.vue +0 -216
  71. package/components/forms/toggle-switch/variants/ToggleSwitchWithLabel.vue +0 -105
  72. package/components/forms/toggle-switch/variants/ToggleSwitchWithLabelInline.vue +0 -102
  73. package/components/forms/ui/FormField.vue +0 -78
  74. package/components/forms/ui/FormWrapper.vue +0 -35
  75. package/components/utils/colour-scheme-select/ColourSchemeSelect.vue +0 -270
  76. package/components/utils/colour-scheme-select/ColourSchemeSelectOld.vue +0 -225
  77. package/components/utils/dark-mode-switcher/DarkModeSwitcher.vue +0 -47
  78. package/composables/useApiRequest.ts +0 -25
  79. package/composables/useColourScheme.ts +0 -25
  80. package/composables/useErrorMessages.ts +0 -59
  81. package/composables/useFormControl.ts +0 -248
  82. package/composables/useSleep.ts +0 -5
  83. package/composables/useStyleClassPassthrough.ts +0 -30
  84. package/composables/useZodValidation.ts +0 -148
  85. package/types/types.forms.ts +0 -216
  86. package/types/types.zodFormControl.ts +0 -21
@@ -1,148 +0,0 @@
1
- import { ref, reactive, toRaw, type Ref } from 'vue';
2
- import { z, ZodError } from 'zod';
3
- import type { ApiErrorResponse } from '../types/types.forms';
4
-
5
- const useZodValidation = (formSchema: any, formRef: Ref<HTMLFormElement | null>) => {
6
- const zodFormControl = reactive({
7
- errorCount: 0,
8
- displayLoader: false,
9
- submitDisabled: false,
10
- submitAttempted: false,
11
- submitSuccessful: false,
12
- formIsValid: false,
13
- isPending: false,
14
- isDisabled: false,
15
- previousState: {} as Record<string, any>,
16
- });
17
-
18
- type formSchema = z.infer<typeof formSchema>;
19
- const zodErrorObj = ref<z.ZodFormattedError<formSchema> | null>(null);
20
-
21
- const resetPreviousValues = () => {
22
- for (const [field] of Object.entries(formSchema.shape)) {
23
- const previousValue = {
24
- value: null,
25
- message: '',
26
- };
27
-
28
- zodFormControl.previousState[field] = previousValue;
29
- }
30
- };
31
-
32
- const initZodForm = () => {
33
- resetPreviousValues();
34
- };
35
-
36
- const getErrorCount = (zodErrorObj: Ref<z.ZodFormattedError<formSchema> | null>) => {
37
- const zodCountErrors = zodErrorObj.value ?? [];
38
- // @ts-ignore
39
- delete zodCountErrors._errors;
40
- const errorCount = Object.keys(zodCountErrors ?? []).length;
41
- return errorCount;
42
- };
43
-
44
- const transformErrorMessages = (errors: any) => {
45
- const apiErrors = ref({}) as any;
46
- for (const [key, value] of Object.entries(errors)) {
47
- const fieldPath = key.split('.').map((key: string) => key.charAt(0).toLowerCase() + key.slice(1));
48
- apiErrors.value[fieldPath.join('.')] = value;
49
- }
50
-
51
- return apiErrors.value;
52
- };
53
-
54
- const updatePreviousValue = async (field: string, message: string, state: Record<string, any>) => {
55
- const previousValue = {
56
- value: state[field],
57
- message: message,
58
- };
59
- zodFormControl.previousState[field] = previousValue;
60
- };
61
-
62
- const pushCustomErrors = async (apiErrorResponse: ApiErrorResponse, state: Record<string, any>) => {
63
- const apiErrors = transformErrorMessages(apiErrorResponse.data.errors);
64
-
65
- // 1: Create a ZodError object to hold the issues
66
- const zodError = new ZodError([]);
67
-
68
- // 2: Reset previous state values
69
- resetPreviousValues();
70
-
71
- // 3: Add issues to the ZodError object
72
- for (const [path, message] of Object.entries(apiErrors)) {
73
- zodError.addIssue({
74
- path: path.split('.'),
75
- message: message as string,
76
- code: z.ZodIssueCode.custom,
77
- });
78
- await updatePreviousValue(path, message as string, state);
79
- }
80
-
81
- zodErrorObj.value = zodError.format();
82
- zodFormControl.errorCount = getErrorCount(zodErrorObj);
83
- zodFormControl.formIsValid = zodFormControl.errorCount === 0;
84
- zodFormControl.displayLoader = false;
85
- zodFormControl.submitAttempted = true;
86
- scrollToFirstError();
87
- return zodErrorObj.value;
88
- };
89
-
90
- const doZodValidate = async (state: Record<string, any>) => {
91
- const valid = formSchema.safeParse(toRaw(state));
92
- if (!valid.success) {
93
- zodErrorObj.value = valid.error.format();
94
- } else {
95
- zodErrorObj.value = null;
96
- }
97
-
98
- zodFormControl.errorCount = getErrorCount(zodErrorObj);
99
- zodFormControl.formIsValid = valid.success;
100
-
101
- return valid.success;
102
- };
103
-
104
- const fieldMaxLength = (name: string) => {
105
- const fieldSchema = formSchema.shape[name];
106
- if (fieldSchema instanceof z.ZodString) {
107
- return fieldSchema._def.checks.find((check) => check.kind === 'max')?.value;
108
- }
109
- };
110
-
111
- const scrollToFirstError = async () => {
112
- if (formRef.value) {
113
- const firstErrorElement = formRef.value.querySelector('[aria-invalid=true]');
114
-
115
- if (firstErrorElement) {
116
- window.scrollTo({
117
- top: firstErrorElement?.getBoundingClientRect().y + window.scrollY,
118
- left: 0,
119
- behavior: 'smooth',
120
- });
121
- }
122
- }
123
- };
124
-
125
- const scrollToFormHead = () => {
126
- if (formRef.value) {
127
- const formHead = formRef.value.getBoundingClientRect().top;
128
- window.scrollTo({
129
- top: formHead,
130
- left: 0,
131
- behavior: 'smooth',
132
- });
133
- }
134
- };
135
-
136
- return {
137
- initZodForm,
138
- zodFormControl,
139
- zodErrorObj,
140
- pushCustomErrors,
141
- doZodValidate,
142
- fieldMaxLength,
143
- scrollToFirstError,
144
- scrollToFormHead,
145
- };
146
- };
147
-
148
- export default useZodValidation;
@@ -1,216 +0,0 @@
1
- export interface IValidationPatterns {
2
- pattern: string;
3
- minlength: string;
4
- maxlength: string;
5
- hint: string;
6
- }
7
-
8
- export interface IOptionsConfig {
9
- id: string;
10
- name: string;
11
- value: string;
12
- label: string;
13
- }
14
-
15
- export interface IFormMultipleOptions {
16
- data: IOptionsConfig[];
17
- total: number;
18
- skip: number;
19
- limit: number;
20
- }
21
-
22
- export interface IOptionsValueArr {
23
- [key: string]: string | boolean | number | URL | object;
24
- }
25
-
26
- export interface IFieldsInitialState {
27
- [key: string]: null | string | boolean | number | URL | object | IOptionsValueArr[];
28
- }
29
-
30
- export type TFieldsInitialState = {
31
- [key: string]: null | string | boolean | number | URL | object | IOptionsValueArr[];
32
- };
33
-
34
- export interface IValidityState {
35
- badInput: boolean;
36
- customError: boolean;
37
- patternMismatch: boolean;
38
- rangeOverflow: boolean;
39
- rangeUnderflow: boolean;
40
- stepMismatch: boolean;
41
- tooLong: boolean;
42
- tooShort: boolean;
43
- typeMismatch: boolean;
44
- valid: boolean;
45
- valueMissing: boolean;
46
- }
47
-
48
- export interface IValidityStateArr {
49
- [key: string]: {
50
- badInput: boolean;
51
- customError: boolean;
52
- patternMismatch: boolean;
53
- rangeOverflow: boolean;
54
- rangeUnderflow: boolean;
55
- stepMismatch: boolean;
56
- tooLong: boolean;
57
- tooShort: boolean;
58
- typeMismatch: boolean;
59
- valid: boolean;
60
- valueMissing: boolean;
61
- };
62
- }
63
-
64
- export interface IFormFieldsState {
65
- [key: string]: boolean;
66
- }
67
-
68
- export interface ICustomErrorMessage {
69
- useCustomError: boolean;
70
- message: string;
71
- }
72
-
73
- export interface InpuTextC12 {
74
- label: string;
75
- placeholder: string;
76
- errorMessage: string;
77
- }
78
-
79
- export interface IErrorMessagesArr {
80
- [x: string]: ICustomErrorMessage;
81
- }
82
-
83
- export interface IFormFieldC12 {
84
- label: string;
85
- placeholder: string;
86
- errorMessage: string;
87
- useCustomError: boolean;
88
- customErrors: null | string | string[];
89
- isValid: boolean;
90
- isDirty: boolean;
91
- type: string;
92
- previousValue: null | string | boolean | number | URL | object;
93
- }
94
-
95
- export interface IFormFieldsC12 {
96
- [x: string]: IFormFieldC12;
97
- }
98
-
99
- export interface IFormFieldState {
100
- isValid: boolean;
101
- isDirty: boolean;
102
- previousValue: null | string | boolean | number | URL | object;
103
- }
104
-
105
- export interface IFormFieldStateObj {
106
- [x: string]: IFormFieldState;
107
- }
108
-
109
- export interface IFormData {
110
- [x: string]: string | boolean | number | URL | object;
111
- data: IFieldsInitialState;
112
- validityState: IFormFieldsState;
113
- dirtyFields: IFormFieldsState;
114
- focusedField: string;
115
- isPending: boolean;
116
- errorCount: number;
117
- errorMessages: IErrorMessagesArr;
118
- formFieldsC12: IFormFieldsC12;
119
- formIsValid: boolean;
120
- submitAttempted: boolean;
121
- submitDisabled: boolean;
122
- submitSuccess: boolean;
123
- displayErrorMessages: boolean;
124
- }
125
-
126
- export interface IApiErrorMessages {
127
- [x: string]: string;
128
- }
129
-
130
- // New types
131
-
132
- export interface C12nInputText {
133
- type: string;
134
- id: string;
135
- name: string;
136
- label: string;
137
- placeholder: string;
138
- errorMessage: string;
139
- fieldHasError: boolean;
140
- required: boolean;
141
- styleClassPassthrough: string[];
142
- }
143
-
144
- export interface C12nMultipleCheckboxes {
145
- id: string;
146
- name: string;
147
- label: string;
148
- legend: string;
149
- placeholder: string;
150
- errorMessage: string;
151
- fieldHasError: boolean;
152
- required: boolean;
153
- styleClassPassthrough: string[];
154
- }
155
-
156
- export interface C12nInputCheckboxWithLabel {
157
- id: string;
158
- name: string;
159
- required: string;
160
- label: string;
161
- placeholder: string;
162
- errorMessage: string | string[];
163
- fieldHasError: boolean;
164
- styleClassPassthrough: string[];
165
- }
166
-
167
- export interface C12nInputRange {
168
- id: string;
169
- name: string;
170
- label: string;
171
- min: number;
172
- max: number;
173
- step: number;
174
- placeholder: string;
175
- errorMessage: string;
176
- fieldHasError: boolean;
177
- required: boolean;
178
- styleClassPassthrough: string[];
179
- }
180
-
181
- export interface C12nInputTextCore {
182
- type: string;
183
- id: string;
184
- name: string;
185
- label: string;
186
- placeholder: string;
187
- errorMessage: string;
188
- fieldHasError: boolean;
189
- required: boolean;
190
- }
191
-
192
- export interface InputTextWithLabel {
193
- type: string;
194
- id: string;
195
- name: string;
196
- label: string;
197
- placeholder: string;
198
- errorMessage: string;
199
- fieldHasError: boolean;
200
- required: boolean;
201
- styleClassPassthrough: string[];
202
- deepCssClassPassthrough: string[];
203
- }
204
-
205
- export interface ApiErrorResponse {
206
- url: string;
207
- statusCode: number;
208
- statusMessage: string;
209
- message: string;
210
- stack: string;
211
- data: {
212
- errors: {
213
- [key: string]: string | string[]; // Index signature for dynamic keys
214
- };
215
- };
216
- }
@@ -1,21 +0,0 @@
1
- import type { IFieldsInitialState, IFormFieldsState, IFormFieldsC12, IFormFieldC12, IApiErrorMessages, ICustomErrorMessage, IErrorMessagesArr } from '@/types/types.forms';
2
-
3
- export interface IZodeFormControl {
4
- [x: string]: string | boolean | number | URL | object;
5
- data: IFieldsInitialState;
6
- validityState: IFormFieldsState;
7
- dirtyFields: IFormFieldsState;
8
- focusedField: string;
9
- isDisabled: boolean;
10
- isPending: boolean;
11
- errorCount: number;
12
- errorMessages: IErrorMessagesArr;
13
- formFieldsC12: IFormFieldsC12;
14
- formIsValid: boolean;
15
- submitAttempted: boolean;
16
- submitDisabled: boolean;
17
- submitSuccess: boolean;
18
- displayErrorMessages: boolean;
19
- displayLoader: boolean;
20
- submitSuccessful: boolean;
21
- }