easy-forms-core 1.0.6 → 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 +24 -0
- package/dist/easy-form.js +609 -3
- package/dist/easy-form.js.map +1 -1
- package/dist/index.d.ts +48 -1
- package/dist/index.js +617 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/easy-form.js
CHANGED
|
@@ -3241,6 +3241,516 @@ function getCustomComponent(type) {
|
|
|
3241
3241
|
return customComponents.get(type);
|
|
3242
3242
|
}
|
|
3243
3243
|
|
|
3244
|
+
// src/templates/index.ts
|
|
3245
|
+
var loginTemplate = {
|
|
3246
|
+
fields: [
|
|
3247
|
+
{
|
|
3248
|
+
type: "email",
|
|
3249
|
+
name: "email",
|
|
3250
|
+
label: "Email",
|
|
3251
|
+
placeholder: "Enter your email",
|
|
3252
|
+
validations: [
|
|
3253
|
+
{ type: "required", message: "Email is required" },
|
|
3254
|
+
{ type: "email", message: "Please enter a valid email" }
|
|
3255
|
+
]
|
|
3256
|
+
},
|
|
3257
|
+
{
|
|
3258
|
+
type: "password",
|
|
3259
|
+
name: "password",
|
|
3260
|
+
label: "Password",
|
|
3261
|
+
placeholder: "Enter your password",
|
|
3262
|
+
validations: [
|
|
3263
|
+
{ type: "required", message: "Password is required" },
|
|
3264
|
+
{ type: "minLength", value: 6, message: "Password must be at least 6 characters" }
|
|
3265
|
+
]
|
|
3266
|
+
},
|
|
3267
|
+
{
|
|
3268
|
+
type: "checkbox",
|
|
3269
|
+
name: "rememberMe",
|
|
3270
|
+
label: "Remember me",
|
|
3271
|
+
defaultValue: false
|
|
3272
|
+
}
|
|
3273
|
+
]
|
|
3274
|
+
};
|
|
3275
|
+
var registerTemplate = {
|
|
3276
|
+
fields: [
|
|
3277
|
+
{
|
|
3278
|
+
type: "text",
|
|
3279
|
+
name: "name",
|
|
3280
|
+
label: "Full Name",
|
|
3281
|
+
placeholder: "Enter your full name",
|
|
3282
|
+
validations: [
|
|
3283
|
+
{ type: "required", message: "Name is required" },
|
|
3284
|
+
{ type: "minLength", value: 2, message: "Name must be at least 2 characters" }
|
|
3285
|
+
]
|
|
3286
|
+
},
|
|
3287
|
+
{
|
|
3288
|
+
type: "email",
|
|
3289
|
+
name: "email",
|
|
3290
|
+
label: "Email",
|
|
3291
|
+
placeholder: "Enter your email",
|
|
3292
|
+
validations: [
|
|
3293
|
+
{ type: "required", message: "Email is required" },
|
|
3294
|
+
{ type: "email", message: "Please enter a valid email" }
|
|
3295
|
+
]
|
|
3296
|
+
},
|
|
3297
|
+
{
|
|
3298
|
+
type: "password",
|
|
3299
|
+
name: "password",
|
|
3300
|
+
label: "Password",
|
|
3301
|
+
placeholder: "Create a password",
|
|
3302
|
+
validations: [
|
|
3303
|
+
{ type: "required", message: "Password is required" },
|
|
3304
|
+
{ type: "minLength", value: 8, message: "Password must be at least 8 characters" }
|
|
3305
|
+
]
|
|
3306
|
+
},
|
|
3307
|
+
{
|
|
3308
|
+
type: "password",
|
|
3309
|
+
name: "confirmPassword",
|
|
3310
|
+
label: "Confirm Password",
|
|
3311
|
+
placeholder: "Confirm your password",
|
|
3312
|
+
validations: [
|
|
3313
|
+
{ type: "required", message: "Please confirm your password" },
|
|
3314
|
+
{
|
|
3315
|
+
type: "custom",
|
|
3316
|
+
validator: (value) => {
|
|
3317
|
+
return typeof value === "string" && value.length >= 8;
|
|
3318
|
+
},
|
|
3319
|
+
message: "Password must be at least 8 characters"
|
|
3320
|
+
}
|
|
3321
|
+
]
|
|
3322
|
+
}
|
|
3323
|
+
]
|
|
3324
|
+
};
|
|
3325
|
+
var otpTemplate = {
|
|
3326
|
+
fields: [
|
|
3327
|
+
{
|
|
3328
|
+
type: "otp",
|
|
3329
|
+
name: "code",
|
|
3330
|
+
label: "Verification Code",
|
|
3331
|
+
validations: [
|
|
3332
|
+
{ type: "required", message: "Verification code is required" }
|
|
3333
|
+
]
|
|
3334
|
+
}
|
|
3335
|
+
]
|
|
3336
|
+
};
|
|
3337
|
+
var contactTemplate = {
|
|
3338
|
+
fields: [
|
|
3339
|
+
{
|
|
3340
|
+
type: "text",
|
|
3341
|
+
name: "name",
|
|
3342
|
+
label: "Name",
|
|
3343
|
+
placeholder: "Enter your name",
|
|
3344
|
+
validations: [
|
|
3345
|
+
{ type: "required", message: "Name is required" }
|
|
3346
|
+
]
|
|
3347
|
+
},
|
|
3348
|
+
{
|
|
3349
|
+
type: "email",
|
|
3350
|
+
name: "email",
|
|
3351
|
+
label: "Email",
|
|
3352
|
+
placeholder: "Enter your email",
|
|
3353
|
+
validations: [
|
|
3354
|
+
{ type: "required", message: "Email is required" },
|
|
3355
|
+
{ type: "email", message: "Please enter a valid email" }
|
|
3356
|
+
]
|
|
3357
|
+
},
|
|
3358
|
+
{
|
|
3359
|
+
type: "text",
|
|
3360
|
+
name: "subject",
|
|
3361
|
+
label: "Subject",
|
|
3362
|
+
placeholder: "Enter the subject",
|
|
3363
|
+
validations: [
|
|
3364
|
+
{ type: "required", message: "Subject is required" }
|
|
3365
|
+
]
|
|
3366
|
+
},
|
|
3367
|
+
{
|
|
3368
|
+
type: "textarea",
|
|
3369
|
+
name: "message",
|
|
3370
|
+
label: "Message",
|
|
3371
|
+
placeholder: "Enter your message",
|
|
3372
|
+
rows: 5,
|
|
3373
|
+
validations: [
|
|
3374
|
+
{ type: "required", message: "Message is required" },
|
|
3375
|
+
{ type: "minLength", value: 10, message: "Message must be at least 10 characters" }
|
|
3376
|
+
]
|
|
3377
|
+
}
|
|
3378
|
+
]
|
|
3379
|
+
};
|
|
3380
|
+
var passwordResetTemplate = {
|
|
3381
|
+
fields: [
|
|
3382
|
+
{
|
|
3383
|
+
type: "email",
|
|
3384
|
+
name: "email",
|
|
3385
|
+
label: "Email",
|
|
3386
|
+
placeholder: "Enter your email address",
|
|
3387
|
+
validations: [
|
|
3388
|
+
{ type: "required", message: "Email is required" },
|
|
3389
|
+
{ type: "email", message: "Please enter a valid email" }
|
|
3390
|
+
]
|
|
3391
|
+
}
|
|
3392
|
+
]
|
|
3393
|
+
};
|
|
3394
|
+
var passwordChangeTemplate = {
|
|
3395
|
+
fields: [
|
|
3396
|
+
{
|
|
3397
|
+
type: "password",
|
|
3398
|
+
name: "currentPassword",
|
|
3399
|
+
label: "Current Password",
|
|
3400
|
+
placeholder: "Enter your current password",
|
|
3401
|
+
validations: [
|
|
3402
|
+
{ type: "required", message: "Current password is required" }
|
|
3403
|
+
]
|
|
3404
|
+
},
|
|
3405
|
+
{
|
|
3406
|
+
type: "password",
|
|
3407
|
+
name: "newPassword",
|
|
3408
|
+
label: "New Password",
|
|
3409
|
+
placeholder: "Enter your new password",
|
|
3410
|
+
validations: [
|
|
3411
|
+
{ type: "required", message: "New password is required" },
|
|
3412
|
+
{ type: "minLength", value: 8, message: "Password must be at least 8 characters" }
|
|
3413
|
+
]
|
|
3414
|
+
},
|
|
3415
|
+
{
|
|
3416
|
+
type: "password",
|
|
3417
|
+
name: "confirmPassword",
|
|
3418
|
+
label: "Confirm New Password",
|
|
3419
|
+
placeholder: "Confirm your new password",
|
|
3420
|
+
validations: [
|
|
3421
|
+
{ type: "required", message: "Please confirm your new password" },
|
|
3422
|
+
{
|
|
3423
|
+
type: "custom",
|
|
3424
|
+
validator: (value) => {
|
|
3425
|
+
return typeof value === "string" && value.length >= 8;
|
|
3426
|
+
},
|
|
3427
|
+
message: "Password must be at least 8 characters"
|
|
3428
|
+
}
|
|
3429
|
+
]
|
|
3430
|
+
}
|
|
3431
|
+
]
|
|
3432
|
+
};
|
|
3433
|
+
var profileTemplate = {
|
|
3434
|
+
fields: [
|
|
3435
|
+
{
|
|
3436
|
+
type: "text",
|
|
3437
|
+
name: "name",
|
|
3438
|
+
label: "Full Name",
|
|
3439
|
+
placeholder: "Enter your full name",
|
|
3440
|
+
validations: [
|
|
3441
|
+
{ type: "required", message: "Name is required" }
|
|
3442
|
+
]
|
|
3443
|
+
},
|
|
3444
|
+
{
|
|
3445
|
+
type: "email",
|
|
3446
|
+
name: "email",
|
|
3447
|
+
label: "Email",
|
|
3448
|
+
placeholder: "Enter your email",
|
|
3449
|
+
validations: [
|
|
3450
|
+
{ type: "required", message: "Email is required" },
|
|
3451
|
+
{ type: "email", message: "Please enter a valid email" }
|
|
3452
|
+
]
|
|
3453
|
+
},
|
|
3454
|
+
{
|
|
3455
|
+
type: "text",
|
|
3456
|
+
name: "phone",
|
|
3457
|
+
label: "Phone",
|
|
3458
|
+
placeholder: "Enter your phone number",
|
|
3459
|
+
mask: {
|
|
3460
|
+
type: "phone"
|
|
3461
|
+
}
|
|
3462
|
+
},
|
|
3463
|
+
{
|
|
3464
|
+
type: "textarea",
|
|
3465
|
+
name: "bio",
|
|
3466
|
+
label: "Bio",
|
|
3467
|
+
placeholder: "Tell us about yourself",
|
|
3468
|
+
rows: 4
|
|
3469
|
+
},
|
|
3470
|
+
{
|
|
3471
|
+
type: "file",
|
|
3472
|
+
name: "avatar",
|
|
3473
|
+
label: "Profile Picture",
|
|
3474
|
+
accept: "image/*"
|
|
3475
|
+
}
|
|
3476
|
+
]
|
|
3477
|
+
};
|
|
3478
|
+
var checkoutTemplate = {
|
|
3479
|
+
fields: [
|
|
3480
|
+
{
|
|
3481
|
+
type: "group",
|
|
3482
|
+
name: "billingAddress",
|
|
3483
|
+
label: "Billing Address",
|
|
3484
|
+
fields: [
|
|
3485
|
+
{
|
|
3486
|
+
type: "text",
|
|
3487
|
+
name: "street",
|
|
3488
|
+
label: "Street Address",
|
|
3489
|
+
placeholder: "Enter street address",
|
|
3490
|
+
validations: [
|
|
3491
|
+
{ type: "required", message: "Street address is required" }
|
|
3492
|
+
]
|
|
3493
|
+
},
|
|
3494
|
+
{
|
|
3495
|
+
type: "row",
|
|
3496
|
+
name: "cityState",
|
|
3497
|
+
fields: [
|
|
3498
|
+
{
|
|
3499
|
+
type: "text",
|
|
3500
|
+
name: "city",
|
|
3501
|
+
label: "City",
|
|
3502
|
+
placeholder: "City",
|
|
3503
|
+
validations: [
|
|
3504
|
+
{ type: "required", message: "City is required" }
|
|
3505
|
+
]
|
|
3506
|
+
},
|
|
3507
|
+
{
|
|
3508
|
+
type: "text",
|
|
3509
|
+
name: "state",
|
|
3510
|
+
label: "State",
|
|
3511
|
+
placeholder: "State",
|
|
3512
|
+
validations: [
|
|
3513
|
+
{ type: "required", message: "State is required" }
|
|
3514
|
+
]
|
|
3515
|
+
}
|
|
3516
|
+
]
|
|
3517
|
+
},
|
|
3518
|
+
{
|
|
3519
|
+
type: "text",
|
|
3520
|
+
name: "zipCode",
|
|
3521
|
+
label: "ZIP Code",
|
|
3522
|
+
placeholder: "ZIP Code",
|
|
3523
|
+
validations: [
|
|
3524
|
+
{ type: "required", message: "ZIP code is required" }
|
|
3525
|
+
]
|
|
3526
|
+
}
|
|
3527
|
+
]
|
|
3528
|
+
},
|
|
3529
|
+
{
|
|
3530
|
+
type: "select",
|
|
3531
|
+
name: "paymentMethod",
|
|
3532
|
+
label: "Payment Method",
|
|
3533
|
+
options: [
|
|
3534
|
+
{ label: "Credit Card", value: "credit-card" },
|
|
3535
|
+
{ label: "Debit Card", value: "debit-card" },
|
|
3536
|
+
{ label: "PayPal", value: "paypal" },
|
|
3537
|
+
{ label: "Bank Transfer", value: "bank-transfer" }
|
|
3538
|
+
],
|
|
3539
|
+
validations: [
|
|
3540
|
+
{ type: "required", message: "Payment method is required" }
|
|
3541
|
+
]
|
|
3542
|
+
},
|
|
3543
|
+
{
|
|
3544
|
+
type: "select",
|
|
3545
|
+
name: "shipping",
|
|
3546
|
+
label: "Shipping Method",
|
|
3547
|
+
options: [
|
|
3548
|
+
{ label: "Standard (5-7 days)", value: "standard" },
|
|
3549
|
+
{ label: "Express (2-3 days)", value: "express" },
|
|
3550
|
+
{ label: "Overnight", value: "overnight" }
|
|
3551
|
+
],
|
|
3552
|
+
validations: [
|
|
3553
|
+
{ type: "required", message: "Shipping method is required" }
|
|
3554
|
+
]
|
|
3555
|
+
}
|
|
3556
|
+
]
|
|
3557
|
+
};
|
|
3558
|
+
var feedbackTemplate = {
|
|
3559
|
+
fields: [
|
|
3560
|
+
{
|
|
3561
|
+
type: "select",
|
|
3562
|
+
name: "rating",
|
|
3563
|
+
label: "Rating",
|
|
3564
|
+
options: [
|
|
3565
|
+
{ label: "1 - Poor", value: 1 },
|
|
3566
|
+
{ label: "2 - Fair", value: 2 },
|
|
3567
|
+
{ label: "3 - Good", value: 3 },
|
|
3568
|
+
{ label: "4 - Very Good", value: 4 },
|
|
3569
|
+
{ label: "5 - Excellent", value: 5 }
|
|
3570
|
+
],
|
|
3571
|
+
validations: [
|
|
3572
|
+
{ type: "required", message: "Rating is required" }
|
|
3573
|
+
]
|
|
3574
|
+
},
|
|
3575
|
+
{
|
|
3576
|
+
type: "textarea",
|
|
3577
|
+
name: "comment",
|
|
3578
|
+
label: "Comment",
|
|
3579
|
+
placeholder: "Share your feedback",
|
|
3580
|
+
rows: 5,
|
|
3581
|
+
validations: [
|
|
3582
|
+
{ type: "required", message: "Comment is required" }
|
|
3583
|
+
]
|
|
3584
|
+
},
|
|
3585
|
+
{
|
|
3586
|
+
type: "email",
|
|
3587
|
+
name: "email",
|
|
3588
|
+
label: "Email (optional)",
|
|
3589
|
+
placeholder: "Enter your email if you want a response"
|
|
3590
|
+
}
|
|
3591
|
+
]
|
|
3592
|
+
};
|
|
3593
|
+
var subscriptionTemplate = {
|
|
3594
|
+
fields: [
|
|
3595
|
+
{
|
|
3596
|
+
type: "email",
|
|
3597
|
+
name: "email",
|
|
3598
|
+
label: "Email",
|
|
3599
|
+
placeholder: "Enter your email",
|
|
3600
|
+
validations: [
|
|
3601
|
+
{ type: "required", message: "Email is required" },
|
|
3602
|
+
{ type: "email", message: "Please enter a valid email" }
|
|
3603
|
+
]
|
|
3604
|
+
},
|
|
3605
|
+
{
|
|
3606
|
+
type: "checkbox",
|
|
3607
|
+
name: "weeklyNewsletter",
|
|
3608
|
+
label: "Weekly Newsletter",
|
|
3609
|
+
defaultValue: true
|
|
3610
|
+
},
|
|
3611
|
+
{
|
|
3612
|
+
type: "checkbox",
|
|
3613
|
+
name: "productUpdates",
|
|
3614
|
+
label: "Product Updates",
|
|
3615
|
+
defaultValue: false
|
|
3616
|
+
},
|
|
3617
|
+
{
|
|
3618
|
+
type: "checkbox",
|
|
3619
|
+
name: "promotions",
|
|
3620
|
+
label: "Promotions and Special Offers",
|
|
3621
|
+
defaultValue: false
|
|
3622
|
+
}
|
|
3623
|
+
]
|
|
3624
|
+
};
|
|
3625
|
+
var bookingTemplate = {
|
|
3626
|
+
fields: [
|
|
3627
|
+
{
|
|
3628
|
+
type: "date",
|
|
3629
|
+
name: "date",
|
|
3630
|
+
label: "Date",
|
|
3631
|
+
validations: [
|
|
3632
|
+
{ type: "required", message: "Date is required" }
|
|
3633
|
+
]
|
|
3634
|
+
},
|
|
3635
|
+
{
|
|
3636
|
+
type: "text",
|
|
3637
|
+
name: "time",
|
|
3638
|
+
label: "Time",
|
|
3639
|
+
placeholder: "HH:MM",
|
|
3640
|
+
mask: {
|
|
3641
|
+
type: "time"
|
|
3642
|
+
},
|
|
3643
|
+
validations: [
|
|
3644
|
+
{ type: "required", message: "Time is required" }
|
|
3645
|
+
]
|
|
3646
|
+
},
|
|
3647
|
+
{
|
|
3648
|
+
type: "number",
|
|
3649
|
+
name: "guests",
|
|
3650
|
+
label: "Number of Guests",
|
|
3651
|
+
placeholder: "Enter number of guests",
|
|
3652
|
+
min: 1,
|
|
3653
|
+
max: 20,
|
|
3654
|
+
validations: [
|
|
3655
|
+
{ type: "required", message: "Number of guests is required" },
|
|
3656
|
+
{ type: "min", value: 1, message: "At least 1 guest is required" }
|
|
3657
|
+
]
|
|
3658
|
+
},
|
|
3659
|
+
{
|
|
3660
|
+
type: "textarea",
|
|
3661
|
+
name: "specialRequests",
|
|
3662
|
+
label: "Special Requests",
|
|
3663
|
+
placeholder: "Any special requests or dietary restrictions?",
|
|
3664
|
+
rows: 4
|
|
3665
|
+
}
|
|
3666
|
+
]
|
|
3667
|
+
};
|
|
3668
|
+
var reviewTemplate = {
|
|
3669
|
+
fields: [
|
|
3670
|
+
{
|
|
3671
|
+
type: "select",
|
|
3672
|
+
name: "rating",
|
|
3673
|
+
label: "Rating",
|
|
3674
|
+
options: [
|
|
3675
|
+
{ label: "1 Star", value: 1 },
|
|
3676
|
+
{ label: "2 Stars", value: 2 },
|
|
3677
|
+
{ label: "3 Stars", value: 3 },
|
|
3678
|
+
{ label: "4 Stars", value: 4 },
|
|
3679
|
+
{ label: "5 Stars", value: 5 }
|
|
3680
|
+
],
|
|
3681
|
+
validations: [
|
|
3682
|
+
{ type: "required", message: "Rating is required" }
|
|
3683
|
+
]
|
|
3684
|
+
},
|
|
3685
|
+
{
|
|
3686
|
+
type: "text",
|
|
3687
|
+
name: "title",
|
|
3688
|
+
label: "Review Title",
|
|
3689
|
+
placeholder: "Give your review a title",
|
|
3690
|
+
validations: [
|
|
3691
|
+
{ type: "required", message: "Review title is required" },
|
|
3692
|
+
{ type: "minLength", value: 5, message: "Title must be at least 5 characters" }
|
|
3693
|
+
]
|
|
3694
|
+
},
|
|
3695
|
+
{
|
|
3696
|
+
type: "textarea",
|
|
3697
|
+
name: "comment",
|
|
3698
|
+
label: "Your Review",
|
|
3699
|
+
placeholder: "Share your experience",
|
|
3700
|
+
rows: 6,
|
|
3701
|
+
validations: [
|
|
3702
|
+
{ type: "required", message: "Review comment is required" },
|
|
3703
|
+
{ type: "minLength", value: 20, message: "Review must be at least 20 characters" }
|
|
3704
|
+
]
|
|
3705
|
+
}
|
|
3706
|
+
]
|
|
3707
|
+
};
|
|
3708
|
+
var templates = {
|
|
3709
|
+
login: loginTemplate,
|
|
3710
|
+
register: registerTemplate,
|
|
3711
|
+
otp: otpTemplate,
|
|
3712
|
+
contact: contactTemplate,
|
|
3713
|
+
"password-reset": passwordResetTemplate,
|
|
3714
|
+
"password-change": passwordChangeTemplate,
|
|
3715
|
+
profile: profileTemplate,
|
|
3716
|
+
checkout: checkoutTemplate,
|
|
3717
|
+
feedback: feedbackTemplate,
|
|
3718
|
+
subscription: subscriptionTemplate,
|
|
3719
|
+
booking: bookingTemplate,
|
|
3720
|
+
review: reviewTemplate
|
|
3721
|
+
};
|
|
3722
|
+
function getTemplate(templateName) {
|
|
3723
|
+
if (templateName in templates) {
|
|
3724
|
+
return templates[templateName];
|
|
3725
|
+
}
|
|
3726
|
+
return null;
|
|
3727
|
+
}
|
|
3728
|
+
function extendTemplate(templateName, additionalFields) {
|
|
3729
|
+
const baseTemplate = getTemplate(templateName);
|
|
3730
|
+
if (!baseTemplate) {
|
|
3731
|
+
throw new Error(`Template "${templateName}" not found`);
|
|
3732
|
+
}
|
|
3733
|
+
const existingFields = baseTemplate.fields || [];
|
|
3734
|
+
const existingSteps = baseTemplate.steps;
|
|
3735
|
+
if (existingSteps && existingSteps.length > 0) {
|
|
3736
|
+
const lastStep = existingSteps[existingSteps.length - 1];
|
|
3737
|
+
return {
|
|
3738
|
+
...baseTemplate,
|
|
3739
|
+
steps: [
|
|
3740
|
+
...existingSteps.slice(0, -1),
|
|
3741
|
+
{
|
|
3742
|
+
...lastStep,
|
|
3743
|
+
fields: [...lastStep.fields, ...additionalFields]
|
|
3744
|
+
}
|
|
3745
|
+
]
|
|
3746
|
+
};
|
|
3747
|
+
}
|
|
3748
|
+
return {
|
|
3749
|
+
...baseTemplate,
|
|
3750
|
+
fields: [...existingFields, ...additionalFields]
|
|
3751
|
+
};
|
|
3752
|
+
}
|
|
3753
|
+
|
|
3244
3754
|
// src/components/easy-form.ts
|
|
3245
3755
|
var BrowserHTMLElement = typeof HTMLElement !== "undefined" ? HTMLElement : class {
|
|
3246
3756
|
};
|
|
@@ -3257,7 +3767,7 @@ var EasyForm = class extends BrowserHTMLElement {
|
|
|
3257
3767
|
this.shadow = this.attachShadow({ mode: "open" });
|
|
3258
3768
|
}
|
|
3259
3769
|
static get observedAttributes() {
|
|
3260
|
-
return ["schema", "theme", "colors", "initialData"];
|
|
3770
|
+
return ["schema", "template", "template-extend", "theme", "colors", "initialData"];
|
|
3261
3771
|
}
|
|
3262
3772
|
/**
|
|
3263
3773
|
* Obtiene el schema
|
|
@@ -3265,18 +3775,72 @@ var EasyForm = class extends BrowserHTMLElement {
|
|
|
3265
3775
|
get schema() {
|
|
3266
3776
|
const schemaAttr = this.getAttribute("schema");
|
|
3267
3777
|
if (!schemaAttr) return null;
|
|
3778
|
+
if (this.getAttribute("template")) {
|
|
3779
|
+
console.warn('EasyForm: Cannot use both "schema" and "template" attributes. "template" will be ignored.');
|
|
3780
|
+
return parseAttributeValue(schemaAttr);
|
|
3781
|
+
}
|
|
3268
3782
|
return parseAttributeValue(schemaAttr);
|
|
3269
3783
|
}
|
|
3270
3784
|
/**
|
|
3271
3785
|
* Establece el schema
|
|
3272
3786
|
*/
|
|
3273
3787
|
set schema(value) {
|
|
3788
|
+
if (value && this.getAttribute("template")) {
|
|
3789
|
+
console.warn('EasyForm: Setting "schema" will remove "template" attribute.');
|
|
3790
|
+
this.removeAttribute("template");
|
|
3791
|
+
this.removeAttribute("template-extend");
|
|
3792
|
+
}
|
|
3274
3793
|
if (value) {
|
|
3275
3794
|
this.setAttribute("schema", attributeValue(value));
|
|
3276
3795
|
} else {
|
|
3277
3796
|
this.removeAttribute("schema");
|
|
3278
3797
|
}
|
|
3279
3798
|
}
|
|
3799
|
+
/**
|
|
3800
|
+
* Obtiene el template
|
|
3801
|
+
*/
|
|
3802
|
+
get template() {
|
|
3803
|
+
const templateAttr = this.getAttribute("template");
|
|
3804
|
+
if (!templateAttr) return null;
|
|
3805
|
+
if (this.getAttribute("schema")) {
|
|
3806
|
+
console.warn('EasyForm: Cannot use both "template" and "schema" attributes. "schema" will be ignored.');
|
|
3807
|
+
return templateAttr;
|
|
3808
|
+
}
|
|
3809
|
+
return templateAttr;
|
|
3810
|
+
}
|
|
3811
|
+
/**
|
|
3812
|
+
* Establece el template
|
|
3813
|
+
*/
|
|
3814
|
+
set template(value) {
|
|
3815
|
+
if (value && this.getAttribute("schema")) {
|
|
3816
|
+
console.warn('EasyForm: Setting "template" will remove "schema" attribute.');
|
|
3817
|
+
this.removeAttribute("schema");
|
|
3818
|
+
}
|
|
3819
|
+
if (value) {
|
|
3820
|
+
this.setAttribute("template", value);
|
|
3821
|
+
} else {
|
|
3822
|
+
this.removeAttribute("template");
|
|
3823
|
+
this.removeAttribute("template-extend");
|
|
3824
|
+
}
|
|
3825
|
+
}
|
|
3826
|
+
/**
|
|
3827
|
+
* Obtiene los campos adicionales para extender el template
|
|
3828
|
+
*/
|
|
3829
|
+
get templateExtend() {
|
|
3830
|
+
const extendAttr = this.getAttribute("template-extend");
|
|
3831
|
+
if (!extendAttr) return null;
|
|
3832
|
+
return parseAttributeValue(extendAttr);
|
|
3833
|
+
}
|
|
3834
|
+
/**
|
|
3835
|
+
* Establece los campos adicionales para extender el template
|
|
3836
|
+
*/
|
|
3837
|
+
set templateExtend(value) {
|
|
3838
|
+
if (value) {
|
|
3839
|
+
this.setAttribute("template-extend", attributeValue(value));
|
|
3840
|
+
} else {
|
|
3841
|
+
this.removeAttribute("template-extend");
|
|
3842
|
+
}
|
|
3843
|
+
}
|
|
3280
3844
|
/**
|
|
3281
3845
|
* Se llama cuando el componente se conecta al DOM
|
|
3282
3846
|
*/
|
|
@@ -3289,6 +3853,21 @@ var EasyForm = class extends BrowserHTMLElement {
|
|
|
3289
3853
|
*/
|
|
3290
3854
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
3291
3855
|
if (name === "schema" && newValue !== oldValue) {
|
|
3856
|
+
if (this.getAttribute("template")) {
|
|
3857
|
+
console.warn('EasyForm: "schema" and "template" cannot be used together. Removing "template".');
|
|
3858
|
+
this.removeAttribute("template");
|
|
3859
|
+
this.removeAttribute("template-extend");
|
|
3860
|
+
}
|
|
3861
|
+
this.handleSchemaChange();
|
|
3862
|
+
}
|
|
3863
|
+
if (name === "template" && newValue !== oldValue) {
|
|
3864
|
+
if (this.getAttribute("schema")) {
|
|
3865
|
+
console.warn('EasyForm: "template" and "schema" cannot be used together. Removing "schema".');
|
|
3866
|
+
this.removeAttribute("schema");
|
|
3867
|
+
}
|
|
3868
|
+
this.handleSchemaChange();
|
|
3869
|
+
}
|
|
3870
|
+
if (name === "template-extend" && newValue !== oldValue) {
|
|
3292
3871
|
this.handleSchemaChange();
|
|
3293
3872
|
}
|
|
3294
3873
|
if (name === "initialData" && newValue !== oldValue) {
|
|
@@ -3302,13 +3881,34 @@ var EasyForm = class extends BrowserHTMLElement {
|
|
|
3302
3881
|
* Maneja el cambio de schema
|
|
3303
3882
|
*/
|
|
3304
3883
|
handleSchemaChange() {
|
|
3305
|
-
|
|
3884
|
+
let schema = null;
|
|
3885
|
+
const templateName = this.template;
|
|
3886
|
+
if (templateName) {
|
|
3887
|
+
schema = this.getSchemaFromTemplate(templateName);
|
|
3888
|
+
} else {
|
|
3889
|
+
schema = this.schema;
|
|
3890
|
+
}
|
|
3306
3891
|
if (schema) {
|
|
3307
3892
|
const initialData = this.initialData;
|
|
3308
3893
|
this.stateManager.initializeSchema(schema, initialData || void 0);
|
|
3309
3894
|
this.render();
|
|
3310
3895
|
}
|
|
3311
3896
|
}
|
|
3897
|
+
/**
|
|
3898
|
+
* Obtiene el schema desde un template
|
|
3899
|
+
*/
|
|
3900
|
+
getSchemaFromTemplate(templateName) {
|
|
3901
|
+
const baseTemplate = getTemplate(templateName);
|
|
3902
|
+
if (!baseTemplate) {
|
|
3903
|
+
console.error(`EasyForm: Template "${templateName}" not found`);
|
|
3904
|
+
return null;
|
|
3905
|
+
}
|
|
3906
|
+
const additionalFields = this.templateExtend;
|
|
3907
|
+
if (additionalFields && additionalFields.length > 0) {
|
|
3908
|
+
return extendTemplate(templateName, additionalFields);
|
|
3909
|
+
}
|
|
3910
|
+
return baseTemplate;
|
|
3911
|
+
}
|
|
3312
3912
|
/**
|
|
3313
3913
|
* Renderiza el formulario
|
|
3314
3914
|
*/
|
|
@@ -3318,7 +3918,13 @@ var EasyForm = class extends BrowserHTMLElement {
|
|
|
3318
3918
|
}
|
|
3319
3919
|
this.isRendering = true;
|
|
3320
3920
|
try {
|
|
3321
|
-
|
|
3921
|
+
let schema = null;
|
|
3922
|
+
const templateName = this.template;
|
|
3923
|
+
if (templateName) {
|
|
3924
|
+
schema = this.getSchemaFromTemplate(templateName);
|
|
3925
|
+
} else {
|
|
3926
|
+
schema = this.schema;
|
|
3927
|
+
}
|
|
3322
3928
|
if (!schema) {
|
|
3323
3929
|
const form = this.shadow.querySelector("form");
|
|
3324
3930
|
if (form && form.parentNode === this.shadow) {
|