@tachui/forms 0.7.1-alpha → 0.8.0-alpha
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 +87 -272
- package/dist/DatePicker-D5nRFTUm.js +475 -0
- package/dist/DatePicker-D5nRFTUm.js.map +1 -0
- package/dist/Select-yZyKooXk.js +945 -0
- package/dist/Select-yZyKooXk.js.map +1 -0
- package/dist/Slider-0-oal5YR.js +644 -0
- package/dist/Slider-0-oal5YR.js.map +1 -0
- package/dist/TextField-hX15dY3U.js +509 -0
- package/dist/TextField-hX15dY3U.js.map +1 -0
- package/dist/components/advanced/Slider.d.ts +190 -0
- package/dist/components/advanced/Slider.d.ts.map +1 -0
- package/dist/components/advanced/Stepper.d.ts +161 -0
- package/dist/components/advanced/Stepper.d.ts.map +1 -0
- package/dist/components/advanced/index.d.ts +15 -0
- package/dist/components/advanced/index.d.ts.map +1 -0
- package/dist/components/advanced/index.js +6 -0
- package/dist/components/advanced/index.js.map +1 -0
- package/dist/components/date-picker/DatePicker.d.ts +126 -0
- package/dist/components/date-picker/DatePicker.d.ts.map +1 -0
- package/dist/components/date-picker/index.d.ts +14 -0
- package/dist/components/date-picker/index.d.ts.map +1 -0
- package/dist/components/date-picker/index.js +5 -0
- package/dist/components/date-picker/index.js.map +1 -0
- package/dist/components/form-container/index.d.ts +58 -0
- package/dist/components/form-container/index.d.ts.map +1 -0
- package/dist/components/selection/Checkbox.d.ts.map +1 -0
- package/dist/components/selection/Radio.d.ts.map +1 -0
- package/dist/components/selection/Select.d.ts.map +1 -0
- package/dist/components/selection/index.d.ts +68 -0
- package/dist/components/selection/index.d.ts.map +1 -0
- package/dist/components/selection/index.js +12 -0
- package/dist/components/selection/index.js.map +1 -0
- package/dist/components/text-input/TextField.d.ts.map +1 -0
- package/dist/components/text-input/index.d.ts +8 -0
- package/dist/components/text-input/index.d.ts.map +1 -0
- package/dist/components/text-input/index.js +18 -0
- package/dist/components/text-input/index.js.map +1 -0
- package/dist/{state/index.js → index-D3WfkqVv.js} +15 -8
- package/dist/index-D3WfkqVv.js.map +1 -0
- package/dist/index.d.ts +10 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +198 -376
- package/dist/index.js.map +1 -0
- package/dist/state/index.d.ts.map +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/index.d.ts +19 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/validation/component-validation.d.ts +11 -2
- package/dist/validation/component-validation.d.ts.map +1 -1
- package/dist/validation/index.d.ts.map +1 -1
- package/dist/validation/index.js +282 -191
- package/dist/validation/index.js.map +1 -0
- package/package.json +53 -39
- package/src/components/advanced/Slider.ts +722 -0
- package/src/components/advanced/Stepper.ts +715 -0
- package/src/components/advanced/index.ts +20 -0
- package/src/components/date-picker/DatePicker.ts +925 -0
- package/src/components/date-picker/index.ts +20 -0
- package/src/components/form-container/index.ts +266 -0
- package/src/components/selection/Checkbox.ts +478 -0
- package/src/components/selection/Radio.ts +470 -0
- package/src/components/selection/Select.ts +620 -0
- package/src/components/selection/index.ts +81 -0
- package/src/components/text-input/TextField.ts +728 -0
- package/src/components/text-input/index.ts +35 -0
- package/src/index.ts +48 -0
- package/src/state/index.ts +544 -0
- package/src/types/index.ts +579 -0
- package/src/utils/formatters.ts +184 -0
- package/src/utils/index.ts +57 -0
- package/src/validation/component-validation.ts +429 -0
- package/src/validation/index.ts +641 -0
- package/dist/TextField-CGBM3x7K.js +0 -1799
- package/dist/components/Form.d.ts +0 -76
- package/dist/components/Form.d.ts.map +0 -1
- package/dist/components/index.d.ts +0 -9
- package/dist/components/index.d.ts.map +0 -1
- package/dist/components/index.js +0 -28
- package/dist/components/input/Checkbox.d.ts.map +0 -1
- package/dist/components/input/Radio.d.ts.map +0 -1
- package/dist/components/input/Select.d.ts.map +0 -1
- package/dist/components/input/TextField.d.ts.map +0 -1
- package/dist/components/input/index.d.ts +0 -11
- package/dist/components/input/index.d.ts.map +0 -1
- package/dist/utils/validators.d.ts +0 -101
- package/dist/utils/validators.d.ts.map +0 -1
- /package/dist/components/{input → selection}/Checkbox.d.ts +0 -0
- /package/dist/components/{input → selection}/Radio.d.ts +0 -0
- /package/dist/components/{input → selection}/Select.d.ts +0 -0
- /package/dist/components/{input → text-input}/TextField.d.ts +0 -0
package/dist/validation/index.js
CHANGED
|
@@ -1,229 +1,313 @@
|
|
|
1
|
-
var g = Object.defineProperty;
|
|
2
|
-
var v = (e, t, r) => t in e ? g(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
-
var m = (e, t, r) => v(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
1
|
class s extends Error {
|
|
5
2
|
constructor(t, r) {
|
|
6
3
|
super(t), this.context = r, this.name = "FormsValidationError";
|
|
7
4
|
}
|
|
8
5
|
getFormattedMessage() {
|
|
9
|
-
const { component: t, suggestion: r, example: a, documentation:
|
|
10
|
-
let i = `❌ [@tachui/forms] ${t} Component Error: ${this.message}
|
|
6
|
+
const { component: t, suggestion: r, example: a, documentation: n } = this.context;
|
|
7
|
+
let i = `❌ [@tachui/advanced-forms] ${t} Component Error: ${this.message}
|
|
11
8
|
`;
|
|
12
9
|
return r && (i += `
|
|
13
10
|
💡 Suggestion: ${r}
|
|
14
11
|
`), a && (i += `
|
|
15
12
|
❌ Wrong: ${a.wrong}`, i += `
|
|
16
13
|
✅ Correct: ${a.correct}
|
|
17
|
-
`),
|
|
18
|
-
📚 Documentation: ${
|
|
14
|
+
`), n && (i += `
|
|
15
|
+
📚 Documentation: ${n}`), i;
|
|
19
16
|
}
|
|
20
17
|
}
|
|
21
18
|
const l = {
|
|
22
|
-
//
|
|
23
|
-
|
|
19
|
+
// TextField Component
|
|
20
|
+
validateTextField(e) {
|
|
24
21
|
if (e.length === 0)
|
|
25
|
-
throw new s(
|
|
26
|
-
component
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
throw new s(
|
|
23
|
+
"TextField component requires a props object with name",
|
|
24
|
+
{
|
|
25
|
+
component: "TextField",
|
|
26
|
+
suggestion: 'Add name property: TextField({ name: "fieldName" })',
|
|
27
|
+
documentation: "https://docs.tachui.dev/advanced-forms/components/textfield",
|
|
28
|
+
example: {
|
|
29
|
+
wrong: "TextField()",
|
|
30
|
+
correct: 'TextField({ name: "email", value: emailSignal })'
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
const [t] = e;
|
|
35
|
+
if (!t || typeof t != "object")
|
|
36
|
+
throw new s("TextField requires a props object", {
|
|
37
|
+
component: "TextField",
|
|
38
|
+
suggestion: "Pass a props object with name property",
|
|
29
39
|
example: {
|
|
30
|
-
wrong: "
|
|
31
|
-
correct:
|
|
40
|
+
wrong: 'TextField("email")',
|
|
41
|
+
correct: 'TextField({ name: "email" })'
|
|
32
42
|
}
|
|
33
43
|
});
|
|
44
|
+
const r = t;
|
|
45
|
+
if (!r.name || typeof r.name != "string")
|
|
46
|
+
throw new s(
|
|
47
|
+
"TextField name property is required and must be a string",
|
|
48
|
+
{
|
|
49
|
+
component: "TextField",
|
|
50
|
+
suggestion: "Provide a unique name for the field",
|
|
51
|
+
example: {
|
|
52
|
+
wrong: 'TextField({ placeholder: "Email" })',
|
|
53
|
+
correct: 'TextField({ name: "email", placeholder: "Email" })'
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
},
|
|
58
|
+
// EmailField Component
|
|
59
|
+
validateEmailField(e) {
|
|
60
|
+
if (e.length === 0)
|
|
61
|
+
throw new s(
|
|
62
|
+
"EmailField component requires a props object with name",
|
|
63
|
+
{
|
|
64
|
+
component: "EmailField",
|
|
65
|
+
suggestion: 'Add name property: EmailField({ name: "email" })',
|
|
66
|
+
documentation: "https://docs.tachui.dev/advanced-forms/components/emailfield",
|
|
67
|
+
example: {
|
|
68
|
+
wrong: "EmailField()",
|
|
69
|
+
correct: 'EmailField({ name: "email", value: emailSignal })'
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
);
|
|
34
73
|
const [t] = e;
|
|
35
74
|
if (!t || typeof t != "object")
|
|
36
75
|
throw new s("EmailField requires a props object", {
|
|
37
76
|
component: "EmailField",
|
|
38
|
-
suggestion: "Pass a props object with
|
|
77
|
+
suggestion: "Pass a props object with name property",
|
|
39
78
|
example: {
|
|
40
79
|
wrong: 'EmailField("email@example.com")',
|
|
41
|
-
correct: 'EmailField({ value: "email@example.com" })'
|
|
80
|
+
correct: 'EmailField({ name: "email", value: "email@example.com" })'
|
|
42
81
|
}
|
|
43
82
|
});
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
83
|
+
const r = t;
|
|
84
|
+
if (!r.name || typeof r.name != "string")
|
|
85
|
+
throw new s(
|
|
86
|
+
"EmailField name property is required and must be a string",
|
|
87
|
+
{
|
|
88
|
+
component: "EmailField",
|
|
89
|
+
suggestion: "Provide a unique name for the email field",
|
|
90
|
+
example: {
|
|
91
|
+
wrong: 'EmailField({ placeholder: "Email" })',
|
|
92
|
+
correct: 'EmailField({ name: "email", placeholder: "Email" })'
|
|
93
|
+
}
|
|
51
94
|
}
|
|
52
|
-
|
|
95
|
+
);
|
|
53
96
|
},
|
|
54
97
|
// PasswordField Component
|
|
55
98
|
validatePasswordField(e) {
|
|
56
99
|
if (e.length === 0)
|
|
57
|
-
throw new s(
|
|
58
|
-
component
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
100
|
+
throw new s(
|
|
101
|
+
"PasswordField component requires a props object with name",
|
|
102
|
+
{
|
|
103
|
+
component: "PasswordField",
|
|
104
|
+
suggestion: 'Add name property: PasswordField({ name: "password" })',
|
|
105
|
+
documentation: "https://docs.tachui.dev/advanced-forms/components/passwordfield",
|
|
106
|
+
example: {
|
|
107
|
+
wrong: "PasswordField()",
|
|
108
|
+
correct: 'PasswordField({ name: "password", value: passwordSignal })'
|
|
109
|
+
}
|
|
64
110
|
}
|
|
65
|
-
|
|
111
|
+
);
|
|
66
112
|
const [t] = e;
|
|
67
113
|
if (!t || typeof t != "object")
|
|
68
114
|
throw new s("PasswordField requires a props object", {
|
|
69
115
|
component: "PasswordField",
|
|
70
|
-
suggestion: "Pass a props object with
|
|
116
|
+
suggestion: "Pass a props object with name property",
|
|
71
117
|
example: {
|
|
72
118
|
wrong: 'PasswordField("password")',
|
|
73
|
-
correct:
|
|
119
|
+
correct: 'PasswordField({ name: "password", value: passwordSignal })'
|
|
74
120
|
}
|
|
75
121
|
});
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
122
|
+
const r = t;
|
|
123
|
+
if (!r.name || typeof r.name != "string")
|
|
124
|
+
throw new s(
|
|
125
|
+
"PasswordField name property is required and must be a string",
|
|
126
|
+
{
|
|
127
|
+
component: "PasswordField",
|
|
128
|
+
suggestion: "Provide a unique name for the password field",
|
|
129
|
+
example: {
|
|
130
|
+
wrong: 'PasswordField({ placeholder: "Password" })',
|
|
131
|
+
correct: 'PasswordField({ name: "password", placeholder: "Password" })'
|
|
132
|
+
}
|
|
83
133
|
}
|
|
84
|
-
|
|
134
|
+
);
|
|
85
135
|
},
|
|
86
|
-
// PhoneField Component
|
|
136
|
+
// PhoneField Component
|
|
87
137
|
validatePhoneField(e) {
|
|
88
138
|
if (e.length === 0)
|
|
89
|
-
throw new s(
|
|
90
|
-
component
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
139
|
+
throw new s(
|
|
140
|
+
"PhoneField component requires a props object with name",
|
|
141
|
+
{
|
|
142
|
+
component: "PhoneField",
|
|
143
|
+
suggestion: 'Add name property: PhoneField({ name: "phone" })',
|
|
144
|
+
documentation: "https://docs.tachui.dev/advanced-forms/components/phonefield",
|
|
145
|
+
example: {
|
|
146
|
+
wrong: "PhoneField()",
|
|
147
|
+
correct: 'PhoneField({ name: "phone", format: "US" })'
|
|
148
|
+
}
|
|
96
149
|
}
|
|
97
|
-
|
|
150
|
+
);
|
|
98
151
|
const [t] = e;
|
|
99
152
|
if (!t || typeof t != "object")
|
|
100
153
|
throw new s("PhoneField requires a props object", {
|
|
101
154
|
component: "PhoneField",
|
|
102
|
-
suggestion: "Pass a props object with
|
|
155
|
+
suggestion: "Pass a props object with name property",
|
|
103
156
|
example: {
|
|
104
157
|
wrong: 'PhoneField("(555) 123-4567")',
|
|
105
|
-
correct:
|
|
158
|
+
correct: 'PhoneField({ name: "phone", value: phoneSignal })'
|
|
106
159
|
}
|
|
107
160
|
});
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
161
|
+
const r = t;
|
|
162
|
+
if (!r.name || typeof r.name != "string")
|
|
163
|
+
throw new s(
|
|
164
|
+
"PhoneField name property is required and must be a string",
|
|
165
|
+
{
|
|
166
|
+
component: "PhoneField",
|
|
167
|
+
suggestion: "Provide a unique name for the phone field",
|
|
168
|
+
example: {
|
|
169
|
+
wrong: 'PhoneField({ format: "US" })',
|
|
170
|
+
correct: 'PhoneField({ name: "phone", format: "US" })'
|
|
171
|
+
}
|
|
115
172
|
}
|
|
116
|
-
|
|
173
|
+
);
|
|
117
174
|
},
|
|
118
175
|
// NumberField Component
|
|
119
176
|
validateNumberField(e) {
|
|
120
177
|
if (e.length === 0)
|
|
121
|
-
throw new s(
|
|
122
|
-
component
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
178
|
+
throw new s(
|
|
179
|
+
"NumberField component requires a props object with name",
|
|
180
|
+
{
|
|
181
|
+
component: "NumberField",
|
|
182
|
+
suggestion: 'Add name property: NumberField({ name: "amount" })',
|
|
183
|
+
documentation: "https://docs.tachui.dev/advanced-forms/components/numberfield",
|
|
184
|
+
example: {
|
|
185
|
+
wrong: "NumberField()",
|
|
186
|
+
correct: 'NumberField({ name: "amount", min: 0, max: 100 })'
|
|
187
|
+
}
|
|
128
188
|
}
|
|
129
|
-
|
|
189
|
+
);
|
|
130
190
|
const [t] = e;
|
|
131
191
|
if (!t || typeof t != "object")
|
|
132
192
|
throw new s("NumberField requires a props object", {
|
|
133
193
|
component: "NumberField",
|
|
134
|
-
suggestion: "Pass a props object with
|
|
194
|
+
suggestion: "Pass a props object with name property",
|
|
135
195
|
example: {
|
|
136
196
|
wrong: "NumberField(42)",
|
|
137
|
-
correct:
|
|
197
|
+
correct: 'NumberField({ name: "amount", value: 42 })'
|
|
138
198
|
}
|
|
139
199
|
});
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
200
|
+
const r = t;
|
|
201
|
+
if (!r.name || typeof r.name != "string")
|
|
202
|
+
throw new s(
|
|
203
|
+
"NumberField name property is required and must be a string",
|
|
204
|
+
{
|
|
205
|
+
component: "NumberField",
|
|
206
|
+
suggestion: "Provide a unique name for the number field",
|
|
207
|
+
example: {
|
|
208
|
+
wrong: "NumberField({ min: 0, max: 100 })",
|
|
209
|
+
correct: 'NumberField({ name: "amount", min: 0, max: 100 })'
|
|
210
|
+
}
|
|
147
211
|
}
|
|
148
|
-
|
|
212
|
+
);
|
|
149
213
|
},
|
|
150
214
|
// CreditCardField Component
|
|
151
215
|
validateCreditCardField(e) {
|
|
152
216
|
if (e.length === 0)
|
|
153
|
-
throw new s(
|
|
154
|
-
component
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
217
|
+
throw new s(
|
|
218
|
+
"CreditCardField component requires a props object with name",
|
|
219
|
+
{
|
|
220
|
+
component: "CreditCardField",
|
|
221
|
+
suggestion: 'Add name property: CreditCardField({ name: "cardNumber" })',
|
|
222
|
+
documentation: "https://docs.tachui.dev/advanced-forms/components/creditcardfield",
|
|
223
|
+
example: {
|
|
224
|
+
wrong: "CreditCardField()",
|
|
225
|
+
correct: 'CreditCardField({ name: "cardNumber", onChange: handleChange })'
|
|
226
|
+
}
|
|
160
227
|
}
|
|
161
|
-
|
|
228
|
+
);
|
|
162
229
|
const [t] = e;
|
|
163
230
|
if (!t || typeof t != "object")
|
|
164
|
-
throw new s(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
231
|
+
throw new s(
|
|
232
|
+
"CreditCardField requires a props object",
|
|
233
|
+
{
|
|
234
|
+
component: "CreditCardField",
|
|
235
|
+
suggestion: "Pass a props object with name property",
|
|
236
|
+
example: {
|
|
237
|
+
wrong: 'CreditCardField("4111111111111111")',
|
|
238
|
+
correct: 'CreditCardField({ name: "cardNumber", value: cardSignal })'
|
|
239
|
+
}
|
|
170
240
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
241
|
+
);
|
|
242
|
+
const r = t;
|
|
243
|
+
if (!r.name || typeof r.name != "string")
|
|
244
|
+
throw new s(
|
|
245
|
+
"CreditCardField name property is required and must be a string",
|
|
246
|
+
{
|
|
247
|
+
component: "CreditCardField",
|
|
248
|
+
suggestion: "Provide a unique name for the credit card field",
|
|
249
|
+
example: {
|
|
250
|
+
wrong: 'CreditCardField({ placeholder: "Card Number" })',
|
|
251
|
+
correct: 'CreditCardField({ name: "cardNumber", placeholder: "Card Number" })'
|
|
252
|
+
}
|
|
179
253
|
}
|
|
180
|
-
|
|
254
|
+
);
|
|
181
255
|
}
|
|
182
256
|
// Additional Forms components would go here...
|
|
183
|
-
// (SearchField, URLField, TextArea, ColorField,
|
|
257
|
+
// (SearchField, URLField, TextArea, ColorField, etc.)
|
|
184
258
|
};
|
|
185
|
-
function
|
|
259
|
+
function p() {
|
|
186
260
|
return [
|
|
187
261
|
{
|
|
188
|
-
packageName: "forms",
|
|
262
|
+
packageName: "advanced-forms",
|
|
263
|
+
componentName: "TextField",
|
|
264
|
+
validate: l.validateTextField
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
packageName: "advanced-forms",
|
|
189
268
|
componentName: "EmailField",
|
|
190
269
|
validate: l.validateEmailField
|
|
191
270
|
},
|
|
192
271
|
{
|
|
193
|
-
packageName: "forms",
|
|
272
|
+
packageName: "advanced-forms",
|
|
194
273
|
componentName: "PasswordField",
|
|
195
274
|
validate: l.validatePasswordField
|
|
196
275
|
},
|
|
197
276
|
{
|
|
198
|
-
packageName: "forms",
|
|
277
|
+
packageName: "advanced-forms",
|
|
199
278
|
componentName: "PhoneField",
|
|
200
279
|
validate: l.validatePhoneField
|
|
201
280
|
},
|
|
202
281
|
{
|
|
203
|
-
packageName: "forms",
|
|
282
|
+
packageName: "advanced-forms",
|
|
204
283
|
componentName: "NumberField",
|
|
205
284
|
validate: l.validateNumberField
|
|
206
285
|
},
|
|
207
286
|
{
|
|
208
|
-
packageName: "forms",
|
|
287
|
+
packageName: "advanced-forms",
|
|
209
288
|
componentName: "CreditCardField",
|
|
210
289
|
validate: l.validateCreditCardField
|
|
211
290
|
}
|
|
212
|
-
// Additional validators would be added here for remaining
|
|
291
|
+
// Additional validators would be added here for remaining Forms components
|
|
213
292
|
];
|
|
214
293
|
}
|
|
215
|
-
async function
|
|
294
|
+
async function g() {
|
|
216
295
|
try {
|
|
217
|
-
const { registerComponentValidator: e } = await import("@tachui/core/validation"), t =
|
|
296
|
+
const { registerComponentValidator: e } = await import("@tachui/core/validation"), t = p();
|
|
218
297
|
for (const r of t)
|
|
219
298
|
e(r);
|
|
220
|
-
process.env.NODE_ENV !== "production" && console.info(
|
|
299
|
+
process.env.NODE_ENV !== "production" && console.info(
|
|
300
|
+
`🔍 [@tachui/advanced-forms] Registered ${t.length} component validators`
|
|
301
|
+
);
|
|
221
302
|
} catch (e) {
|
|
222
|
-
process.env.NODE_ENV !== "production" && console.warn(
|
|
303
|
+
process.env.NODE_ENV !== "production" && console.warn(
|
|
304
|
+
"⚠️ [@tachui/advanced-forms] Could not register validators with Core:",
|
|
305
|
+
e
|
|
306
|
+
);
|
|
223
307
|
}
|
|
224
308
|
}
|
|
225
|
-
typeof window < "u" && process.env.NODE_ENV !== "production" && setTimeout(
|
|
226
|
-
const
|
|
309
|
+
typeof window < "u" && process.env.NODE_ENV !== "production" && setTimeout(g, 10);
|
|
310
|
+
const m = {
|
|
227
311
|
required: (e) => ({
|
|
228
312
|
valid: e != null && e !== "",
|
|
229
313
|
message: "This field is required",
|
|
@@ -320,8 +404,8 @@ const u = {
|
|
|
320
404
|
if (!e) return { valid: !0 };
|
|
321
405
|
const t = e.replace(/\s/g, "");
|
|
322
406
|
let r = 0, a = !1;
|
|
323
|
-
for (let
|
|
324
|
-
let i = parseInt(t.charAt(
|
|
407
|
+
for (let n = t.length - 1; n >= 0; n--) {
|
|
408
|
+
let i = parseInt(t.charAt(n));
|
|
325
409
|
a && (i *= 2, i > 9 && (i = i % 10 + 1)), r += i, a = !a;
|
|
326
410
|
}
|
|
327
411
|
return {
|
|
@@ -369,101 +453,101 @@ const u = {
|
|
|
369
453
|
} : { valid: !0 },
|
|
370
454
|
strongPassword: (e) => {
|
|
371
455
|
if (!e) return { valid: !0 };
|
|
372
|
-
const t = /[A-Z]/.test(e), r = /[a-z]/.test(e), a = /\d/.test(e),
|
|
456
|
+
const t = /[A-Z]/.test(e), r = /[a-z]/.test(e), a = /\d/.test(e), n = /\W/.test(e), i = e.length >= 8, o = t && r && a && n && i;
|
|
373
457
|
return {
|
|
374
|
-
valid:
|
|
375
|
-
message:
|
|
458
|
+
valid: o,
|
|
459
|
+
message: o ? void 0 : "Password must be at least 8 characters with uppercase, lowercase, number and special character",
|
|
376
460
|
code: "WEAK_PASSWORD"
|
|
377
461
|
};
|
|
378
462
|
}
|
|
379
463
|
}, c = /* @__PURE__ */ new Map();
|
|
380
|
-
function
|
|
464
|
+
function v(e) {
|
|
381
465
|
c.set(e.name, e);
|
|
382
466
|
}
|
|
383
|
-
function
|
|
467
|
+
function F(e) {
|
|
384
468
|
c.delete(e);
|
|
385
469
|
}
|
|
386
|
-
function
|
|
387
|
-
return [...Object.keys(
|
|
470
|
+
function N() {
|
|
471
|
+
return [...Object.keys(m), ...c.keys()];
|
|
388
472
|
}
|
|
389
|
-
function
|
|
473
|
+
function u(e, t, r) {
|
|
390
474
|
for (const a of t) {
|
|
391
|
-
let
|
|
475
|
+
let n;
|
|
392
476
|
if (typeof a == "string") {
|
|
393
|
-
const i =
|
|
477
|
+
const i = m[a];
|
|
394
478
|
if (i)
|
|
395
|
-
|
|
479
|
+
n = i(e, r?.[a]);
|
|
396
480
|
else {
|
|
397
|
-
const
|
|
398
|
-
if (
|
|
399
|
-
|
|
481
|
+
const o = c.get(a);
|
|
482
|
+
if (o)
|
|
483
|
+
n = o.validate(e, o.options);
|
|
400
484
|
else {
|
|
401
485
|
console.warn(`Unknown validation rule: ${a}`);
|
|
402
486
|
continue;
|
|
403
487
|
}
|
|
404
488
|
}
|
|
405
489
|
} else if ("validate" in a)
|
|
406
|
-
|
|
490
|
+
n = a.validate(e, a.options);
|
|
407
491
|
else {
|
|
408
|
-
const i =
|
|
492
|
+
const i = m[a.name];
|
|
409
493
|
if (i)
|
|
410
|
-
|
|
494
|
+
n = i(e, a.options);
|
|
411
495
|
else {
|
|
412
496
|
console.warn(`Unknown built-in validation rule: ${a.name}`);
|
|
413
497
|
continue;
|
|
414
498
|
}
|
|
415
499
|
}
|
|
416
|
-
if (!
|
|
417
|
-
return
|
|
500
|
+
if (!n.valid)
|
|
501
|
+
return n;
|
|
418
502
|
}
|
|
419
503
|
return { valid: !0 };
|
|
420
504
|
}
|
|
421
|
-
function
|
|
422
|
-
return !t?.rules || t.rules.length === 0 ? { valid: !0 } :
|
|
505
|
+
function b(e, t) {
|
|
506
|
+
return !t?.rules || t.rules.length === 0 ? { valid: !0 } : u(e.value, t.rules);
|
|
423
507
|
}
|
|
424
|
-
async function
|
|
508
|
+
async function f(e, t, r) {
|
|
425
509
|
for (const a of t) {
|
|
426
|
-
let
|
|
510
|
+
let n;
|
|
427
511
|
if (typeof a == "string") {
|
|
428
|
-
const
|
|
429
|
-
if (
|
|
430
|
-
|
|
512
|
+
const o = m[a];
|
|
513
|
+
if (o)
|
|
514
|
+
n = o(e, r?.[a]);
|
|
431
515
|
else {
|
|
432
516
|
const d = c.get(a);
|
|
433
517
|
if (d)
|
|
434
|
-
|
|
518
|
+
n = d.validate(e, d.options);
|
|
435
519
|
else
|
|
436
520
|
continue;
|
|
437
521
|
}
|
|
438
522
|
} else if ("validate" in a)
|
|
439
|
-
|
|
523
|
+
n = a.validate(e, a.options);
|
|
440
524
|
else {
|
|
441
|
-
const
|
|
442
|
-
if (
|
|
443
|
-
|
|
525
|
+
const o = m[a.name];
|
|
526
|
+
if (o)
|
|
527
|
+
n = o(e, a.options);
|
|
444
528
|
else
|
|
445
529
|
continue;
|
|
446
530
|
}
|
|
447
|
-
const i = await Promise.resolve(
|
|
531
|
+
const i = await Promise.resolve(n);
|
|
448
532
|
if (!i.valid)
|
|
449
533
|
return i;
|
|
450
534
|
}
|
|
451
535
|
return { valid: !0 };
|
|
452
536
|
}
|
|
453
|
-
function
|
|
454
|
-
let r, a,
|
|
455
|
-
return (i) => new Promise((
|
|
456
|
-
if (i === a &&
|
|
457
|
-
Promise.resolve(
|
|
537
|
+
function P(e, t = 300) {
|
|
538
|
+
let r, a, n;
|
|
539
|
+
return (i) => new Promise((o) => {
|
|
540
|
+
if (i === a && n) {
|
|
541
|
+
Promise.resolve(n).then(o);
|
|
458
542
|
return;
|
|
459
543
|
}
|
|
460
544
|
a = i, clearTimeout(r), r = setTimeout(async () => {
|
|
461
545
|
try {
|
|
462
|
-
|
|
463
|
-
const d = await Promise.resolve(
|
|
464
|
-
|
|
546
|
+
n = e(i);
|
|
547
|
+
const d = await Promise.resolve(n);
|
|
548
|
+
o(d);
|
|
465
549
|
} catch {
|
|
466
|
-
|
|
550
|
+
o({
|
|
467
551
|
valid: !1,
|
|
468
552
|
message: "Validation error occurred",
|
|
469
553
|
code: "VALIDATION_ERROR"
|
|
@@ -472,7 +556,7 @@ function I(e, t = 300) {
|
|
|
472
556
|
}, t);
|
|
473
557
|
});
|
|
474
558
|
}
|
|
475
|
-
const
|
|
559
|
+
const E = {
|
|
476
560
|
/**
|
|
477
561
|
* Validate that two fields match (e.g., password confirmation)
|
|
478
562
|
*/
|
|
@@ -484,8 +568,8 @@ const A = {
|
|
|
484
568
|
/**
|
|
485
569
|
* Validate that at least one field in a group is filled
|
|
486
570
|
*/
|
|
487
|
-
requireOneOf: (e, t = "At least one field is required") => (r) => e.some((
|
|
488
|
-
const i = r[
|
|
571
|
+
requireOneOf: (e, t = "At least one field is required") => (r) => e.some((n) => {
|
|
572
|
+
const i = r[n];
|
|
489
573
|
return i != null && i !== "";
|
|
490
574
|
}) ? { valid: !0 } : {
|
|
491
575
|
valid: !1,
|
|
@@ -495,9 +579,9 @@ const A = {
|
|
|
495
579
|
/**
|
|
496
580
|
* Validate that a field is required when another field has a specific value
|
|
497
581
|
*/
|
|
498
|
-
requiredWhen: (e, t, r, a = `${e} is required`) => (
|
|
499
|
-
if (
|
|
500
|
-
const i =
|
|
582
|
+
requiredWhen: (e, t, r, a = `${e} is required`) => (n) => {
|
|
583
|
+
if (n[t] === r) {
|
|
584
|
+
const i = n[e];
|
|
501
585
|
return i != null && i !== "" ? { valid: !0 } : {
|
|
502
586
|
valid: !1,
|
|
503
587
|
message: a,
|
|
@@ -510,10 +594,10 @@ const A = {
|
|
|
510
594
|
* Validate date range (start date before end date)
|
|
511
595
|
*/
|
|
512
596
|
dateRange: (e, t, r = "End date must be after start date") => (a) => {
|
|
513
|
-
const
|
|
514
|
-
if (!
|
|
515
|
-
const
|
|
516
|
-
return new Date(i) >=
|
|
597
|
+
const n = a[e], i = a[t];
|
|
598
|
+
if (!n || !i) return { valid: !0 };
|
|
599
|
+
const o = new Date(n);
|
|
600
|
+
return new Date(i) >= o ? { valid: !0 } : {
|
|
517
601
|
valid: !1,
|
|
518
602
|
message: r,
|
|
519
603
|
code: "INVALID_DATE_RANGE"
|
|
@@ -524,7 +608,10 @@ const A = {
|
|
|
524
608
|
password: ["required", { name: "minLength", options: { minLength: 8 } }],
|
|
525
609
|
phone: [
|
|
526
610
|
"required",
|
|
527
|
-
{
|
|
611
|
+
{
|
|
612
|
+
name: "pattern",
|
|
613
|
+
options: { pattern: /^\+?[\d\s-()]+$/, message: "Invalid phone number" }
|
|
614
|
+
}
|
|
528
615
|
],
|
|
529
616
|
url: ["required", "url"],
|
|
530
617
|
positiveNumber: ["required", "number", { name: "min", options: { min: 0 } }],
|
|
@@ -535,9 +622,9 @@ const A = {
|
|
|
535
622
|
{ name: "max", options: { max: 100 } }
|
|
536
623
|
]
|
|
537
624
|
};
|
|
538
|
-
class
|
|
625
|
+
class h {
|
|
626
|
+
messages = {};
|
|
539
627
|
constructor(t = {}) {
|
|
540
|
-
m(this, "messages", {});
|
|
541
628
|
this.messages = t;
|
|
542
629
|
}
|
|
543
630
|
setMessage(t, r) {
|
|
@@ -547,10 +634,13 @@ class F {
|
|
|
547
634
|
this.messages = { ...this.messages, ...t };
|
|
548
635
|
}
|
|
549
636
|
format(t, r) {
|
|
550
|
-
return t.code && this.messages[t.code] ? this.messages[t.code].replace(
|
|
637
|
+
return t.code && this.messages[t.code] ? this.messages[t.code].replace(
|
|
638
|
+
"${field}",
|
|
639
|
+
r || "field"
|
|
640
|
+
) : t.message || "Validation failed";
|
|
551
641
|
}
|
|
552
642
|
}
|
|
553
|
-
const
|
|
643
|
+
const C = new h(), V = {
|
|
554
644
|
/**
|
|
555
645
|
* Check if a validation result represents an error
|
|
556
646
|
*/
|
|
@@ -573,28 +663,29 @@ const R = new F(), L = {
|
|
|
573
663
|
/**
|
|
574
664
|
* Create a validation function from a rule configuration
|
|
575
665
|
*/
|
|
576
|
-
createValidator: (e, t) => (r) =>
|
|
666
|
+
createValidator: (e, t) => (r) => u(r, e, t),
|
|
577
667
|
/**
|
|
578
668
|
* Create an async validation function
|
|
579
669
|
*/
|
|
580
|
-
createAsyncValidator: (e, t) => (r) =>
|
|
670
|
+
createAsyncValidator: (e, t) => (r) => f(r, e, t)
|
|
581
671
|
};
|
|
582
672
|
export {
|
|
583
|
-
|
|
673
|
+
E as CrossFieldValidators,
|
|
584
674
|
l as FormsComponentValidation,
|
|
585
675
|
s as FormsValidationError,
|
|
586
|
-
|
|
587
|
-
|
|
676
|
+
m as VALIDATION_RULES,
|
|
677
|
+
h as ValidationMessageFormatter,
|
|
588
678
|
x as ValidationPresets,
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
679
|
+
V as ValidationUtils,
|
|
680
|
+
P as createDebouncedValidator,
|
|
681
|
+
p as createFormsValidators,
|
|
682
|
+
C as defaultMessageFormatter,
|
|
683
|
+
N as getValidationRules,
|
|
684
|
+
g as registerFormsValidators,
|
|
685
|
+
v as registerValidationRule,
|
|
686
|
+
F as unregisterValidationRule,
|
|
687
|
+
b as validateField,
|
|
688
|
+
u as validateValue,
|
|
689
|
+
f as validateValueAsync
|
|
600
690
|
};
|
|
691
|
+
//# sourceMappingURL=index.js.map
|