easy-forms-core 1.0.5 → 1.0.7
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 +86 -0
- package/dist/easy-form.d.ts +73 -2
- package/dist/easy-form.js +1339 -4
- package/dist/easy-form.js.map +1 -1
- package/dist/index.d.ts +97 -3
- package/dist/index.js +1347 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -144,11 +144,97 @@ const schema = {
|
|
|
144
144
|
</template>
|
|
145
145
|
```
|
|
146
146
|
|
|
147
|
+
## Templates Pre-construidos
|
|
148
|
+
|
|
149
|
+
EasyForms incluye templates pre-construidos para formularios comunes. Puedes usar el atributo `template` en lugar de `schema`. Los templates y schemas son mutuamente excluyentes.
|
|
150
|
+
|
|
151
|
+
### Uso Básico de Templates
|
|
152
|
+
|
|
153
|
+
```html
|
|
154
|
+
<!-- HTML Vanilla -->
|
|
155
|
+
<easy-form template="login"></easy-form>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
```javascript
|
|
159
|
+
import 'easy-forms-core'
|
|
160
|
+
|
|
161
|
+
const form = document.querySelector('easy-form')
|
|
162
|
+
form.template = 'register'
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
```tsx
|
|
166
|
+
// React
|
|
167
|
+
<easy-form template="contact" />
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
```vue
|
|
171
|
+
<!-- Vue -->
|
|
172
|
+
<easy-form template="login" />
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Templates Disponibles
|
|
176
|
+
|
|
177
|
+
1. **login** - Login form (email, password, remember me)
|
|
178
|
+
2. **register** - Registration form (name, email, password, confirm password)
|
|
179
|
+
3. **otp** - OTP verification (6-digit code)
|
|
180
|
+
4. **contact** - Contact form (name, email, subject, message)
|
|
181
|
+
5. **password-reset** - Password reset request (email)
|
|
182
|
+
6. **password-change** - Change password (current, new, confirm)
|
|
183
|
+
7. **profile** - User profile edit (name, email, phone, bio, avatar)
|
|
184
|
+
8. **checkout** - Checkout form (billing address, payment method, shipping)
|
|
185
|
+
9. **feedback** - Feedback form (rating, comment, email)
|
|
186
|
+
10. **subscription** - Newsletter subscription (email, preferences)
|
|
187
|
+
11. **booking** - Booking/reservation (date, time, guests, special requests)
|
|
188
|
+
12. **review** - Review/rating form (rating, title, comment)
|
|
189
|
+
|
|
190
|
+
### Extender Templates
|
|
191
|
+
|
|
192
|
+
Puedes extender un template agregando campos adicionales usando el atributo `template-extend`:
|
|
193
|
+
|
|
194
|
+
```html
|
|
195
|
+
<easy-form
|
|
196
|
+
template="contact"
|
|
197
|
+
template-extend='[{"type": "text", "name": "phone", "label": "Phone", "validations": [{"type": "required"}]}]'>
|
|
198
|
+
</easy-form>
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
O programáticamente:
|
|
202
|
+
|
|
203
|
+
```javascript
|
|
204
|
+
import { extendTemplate } from 'easy-forms-core'
|
|
205
|
+
|
|
206
|
+
const extendedSchema = extendTemplate('register', [
|
|
207
|
+
{
|
|
208
|
+
type: 'text',
|
|
209
|
+
name: 'company',
|
|
210
|
+
label: 'Company',
|
|
211
|
+
validations: [{ type: 'required' }]
|
|
212
|
+
}
|
|
213
|
+
])
|
|
214
|
+
|
|
215
|
+
form.schema = extendedSchema
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Mutua Exclusividad
|
|
219
|
+
|
|
220
|
+
Los atributos `template` y `schema` son mutuamente excluyentes. Si estableces uno, el otro será removido automáticamente:
|
|
221
|
+
|
|
222
|
+
```javascript
|
|
223
|
+
// Si estableces template, schema será removido
|
|
224
|
+
form.template = 'login'
|
|
225
|
+
// schema ahora es null
|
|
226
|
+
|
|
227
|
+
// Si estableces schema, template será removido
|
|
228
|
+
form.schema = { fields: [...] }
|
|
229
|
+
// template ahora es null
|
|
230
|
+
```
|
|
231
|
+
|
|
147
232
|
## Características
|
|
148
233
|
|
|
149
234
|
- Web Component nativo
|
|
150
235
|
- Escrito en TypeScript
|
|
151
236
|
- JSON → Form automático
|
|
237
|
+
- **Templates pre-construidos** - 12 templates comunes listos para usar
|
|
152
238
|
- Validaciones integradas
|
|
153
239
|
- Steps / wizard forms
|
|
154
240
|
- Formularios anidados
|
package/dist/easy-form.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Tipos de campos soportados
|
|
3
3
|
*/
|
|
4
|
-
type FieldType = 'text' | 'email' | 'number' | 'password' | 'textarea' | 'select' | 'checkbox' | 'radio' | 'switch' | 'date' | 'file' | 'array' | 'group' | 'row' | 'custom';
|
|
4
|
+
type FieldType = 'text' | 'email' | 'number' | 'password' | 'textarea' | 'select' | 'checkbox' | 'radio' | 'switch' | 'date' | 'file' | 'array' | 'group' | 'row' | 'custom' | 'quantity' | 'accordion-select' | 'image-grid-select' | 'otp';
|
|
5
5
|
/**
|
|
6
6
|
* Tipos de validaciones soportadas
|
|
7
7
|
*/
|
|
@@ -222,10 +222,57 @@ interface CustomField extends BaseField {
|
|
|
222
222
|
type: 'custom';
|
|
223
223
|
component: string;
|
|
224
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* Campo de cantidad (quantity)
|
|
227
|
+
*/
|
|
228
|
+
interface QuantityField extends BaseField {
|
|
229
|
+
type: 'quantity';
|
|
230
|
+
min?: number;
|
|
231
|
+
max?: number;
|
|
232
|
+
step?: number;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Campo select en acordeón
|
|
236
|
+
*/
|
|
237
|
+
interface AccordionSelectField extends BaseField {
|
|
238
|
+
type: 'accordion-select';
|
|
239
|
+
options: Array<{
|
|
240
|
+
label: string;
|
|
241
|
+
value: any;
|
|
242
|
+
description?: string;
|
|
243
|
+
content?: string | HTMLElement;
|
|
244
|
+
} | string>;
|
|
245
|
+
multiple?: boolean;
|
|
246
|
+
autoExpand?: boolean;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Campo select de imágenes en cuadrícula
|
|
250
|
+
*/
|
|
251
|
+
interface ImageGridSelectField extends BaseField {
|
|
252
|
+
type: 'image-grid-select';
|
|
253
|
+
options: Array<{
|
|
254
|
+
label: string;
|
|
255
|
+
value: any;
|
|
256
|
+
image?: string;
|
|
257
|
+
description?: string;
|
|
258
|
+
} | string>;
|
|
259
|
+
multiple?: boolean;
|
|
260
|
+
columns?: number;
|
|
261
|
+
imageSize?: 'small' | 'medium' | 'large';
|
|
262
|
+
gap?: string;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Campo OTP (código de un solo uso)
|
|
266
|
+
*/
|
|
267
|
+
interface OTPField extends BaseField {
|
|
268
|
+
type: 'otp';
|
|
269
|
+
length?: number;
|
|
270
|
+
numeric?: boolean;
|
|
271
|
+
}
|
|
225
272
|
/**
|
|
226
273
|
* Unión de todos los tipos de campos
|
|
227
274
|
*/
|
|
228
|
-
type Field = TextField | NumberField | TextareaField | SelectField | CheckboxField | RadioField | SwitchField | DateField | FileField | ArrayField | GroupField | RowField | CustomField;
|
|
275
|
+
type Field = TextField | NumberField | TextareaField | SelectField | CheckboxField | RadioField | SwitchField | DateField | FileField | ArrayField | GroupField | RowField | CustomField | QuantityField | AccordionSelectField | ImageGridSelectField | OTPField;
|
|
229
276
|
/**
|
|
230
277
|
* Step para formularios wizard
|
|
231
278
|
*/
|
|
@@ -251,6 +298,10 @@ interface FormColors {
|
|
|
251
298
|
border?: string;
|
|
252
299
|
background?: string;
|
|
253
300
|
}
|
|
301
|
+
/**
|
|
302
|
+
* Template names available
|
|
303
|
+
*/
|
|
304
|
+
type TemplateName = 'login' | 'register' | 'otp' | 'contact' | 'password-reset' | 'password-change' | 'profile' | 'checkout' | 'feedback' | 'subscription' | 'booking' | 'review';
|
|
254
305
|
/**
|
|
255
306
|
* Schema del formulario
|
|
256
307
|
*/
|
|
@@ -298,6 +349,22 @@ declare class EasyForm extends BrowserHTMLElement {
|
|
|
298
349
|
* Establece el schema
|
|
299
350
|
*/
|
|
300
351
|
set schema(value: FormSchema | null);
|
|
352
|
+
/**
|
|
353
|
+
* Obtiene el template
|
|
354
|
+
*/
|
|
355
|
+
get template(): TemplateName | null;
|
|
356
|
+
/**
|
|
357
|
+
* Establece el template
|
|
358
|
+
*/
|
|
359
|
+
set template(value: TemplateName | null);
|
|
360
|
+
/**
|
|
361
|
+
* Obtiene los campos adicionales para extender el template
|
|
362
|
+
*/
|
|
363
|
+
get templateExtend(): Field[] | null;
|
|
364
|
+
/**
|
|
365
|
+
* Establece los campos adicionales para extender el template
|
|
366
|
+
*/
|
|
367
|
+
set templateExtend(value: Field[] | null);
|
|
301
368
|
/**
|
|
302
369
|
* Se llama cuando el componente se conecta al DOM
|
|
303
370
|
*/
|
|
@@ -310,6 +377,10 @@ declare class EasyForm extends BrowserHTMLElement {
|
|
|
310
377
|
* Maneja el cambio de schema
|
|
311
378
|
*/
|
|
312
379
|
private handleSchemaChange;
|
|
380
|
+
/**
|
|
381
|
+
* Obtiene el schema desde un template
|
|
382
|
+
*/
|
|
383
|
+
private getSchemaFromTemplate;
|
|
313
384
|
/**
|
|
314
385
|
* Renderiza el formulario
|
|
315
386
|
*/
|