easy-forms-core 1.1.11 → 1.1.13

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/dist/index.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' | 'quantity' | 'accordion-select' | 'image-grid-select' | 'otp' | 'file-drop' | 'map' | 'rating' | 'slider';
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' | 'file-drop' | 'map' | 'rating' | 'slider' | 'colorpicker';
5
5
  /**
6
6
  * Tipos de validaciones soportadas
7
7
  */
@@ -248,6 +248,14 @@ interface SliderField extends BaseField {
248
248
  step?: number;
249
249
  showValue?: boolean;
250
250
  }
251
+ /**
252
+ * Campo colorpicker (selección de color hex)
253
+ */
254
+ interface ColorpickerField extends BaseField {
255
+ type: 'colorpicker';
256
+ /** Valor por defecto en hex (ej. #6366f1). Default: #000000 */
257
+ defaultValue?: string;
258
+ }
251
259
  /**
252
260
  * Campo array
253
261
  */
@@ -332,7 +340,7 @@ interface OTPField extends BaseField {
332
340
  /**
333
341
  * Unión de todos los tipos de campos
334
342
  */
335
- type Field = TextField | PasswordField | NumberField | TextareaField | SelectField | CheckboxField | RadioField | SwitchField | DateField | FileField | FileDropField | MapField | RatingField | SliderField | ArrayField | GroupField | RowField | CustomField | QuantityField | AccordionSelectField | ImageGridSelectField | OTPField;
343
+ type Field = TextField | PasswordField | NumberField | TextareaField | SelectField | CheckboxField | RadioField | SwitchField | DateField | FileField | FileDropField | MapField | RatingField | SliderField | ColorpickerField | ArrayField | GroupField | RowField | CustomField | QuantityField | AccordionSelectField | ImageGridSelectField | OTPField;
336
344
  /**
337
345
  * Step para formularios wizard
338
346
  */
@@ -357,6 +365,10 @@ interface FormColors {
357
365
  labelColor?: string;
358
366
  border?: string;
359
367
  background?: string;
368
+ /** Fondo del contenedor .easy-form-group */
369
+ groupBackground?: string;
370
+ /** Color del título .easy-form-group-label */
371
+ groupTitle?: string;
360
372
  }
361
373
  /**
362
374
  * Template names available
@@ -1242,4 +1254,4 @@ declare function getAvailableTemplates(): TemplateName[];
1242
1254
  */
1243
1255
  declare function extendTemplate(templateName: string, additionalFields: Field[]): FormSchema;
1244
1256
 
1245
- export { type AccordionSelectField, type ArrayField, AttemptsLock, type AttemptsLockOptions, type BaseField, type BaseValidation, type ChangeEventDetail, type CheckboxField, type ComponentRegistry, ConditionEngine, type ConditionOperator, type CustomComponent, type CustomField, type CustomMask, type CustomValidation, type DateField, EasyForm, type EmailValidation, type ErrorEventDetail, type Field, type FieldCondition, type FieldDependencies, type FieldType, type FileDropField, type FileField, type FormColors, type FormSchema, type FormState, type FormTheme, type GroupField, INJECTION_VALIDATION_MESSAGE, type ImageGridSelectField, type LabelPosition, type MapField, type MaskConfig, MaskEngine, type MaxLengthValidation, type MaxValidation, type MinLengthValidation, type MinValidation, type NoInjectionValidation, type NumberField, type OTPField, PREDEFINED_MASKS, type PasswordField, type PatternValidation, type PredefinedMask, type QuantityField, type RadioField, type RatingField, type RequiredValidation, type RowField, SchemaParser, type SelectField, type SliderField, StateManager, type Step, type StepChangeEventDetail, type SubmitButtonConfig, type SubmitEventDetail, type SwitchField, type TemplateName, type TextField, type TextareaField, type Validation, ValidationEngine, type ValidationType, type WizardState, attributeValue, containsInjection, createInput, extendTemplate, generateId, getAvailableTemplates, getColors, getCustomComponent, getNestedValue, getPredefinedMask, getTemplate, getThemeStyles, isSafeFromInjection, isValidEmail, parseAttributeValue, registerComponent, registerComponents, sanitizeId, setNestedValue, templates };
1257
+ export { type AccordionSelectField, type ArrayField, AttemptsLock, type AttemptsLockOptions, type BaseField, type BaseValidation, type ChangeEventDetail, type CheckboxField, type ColorpickerField, type ComponentRegistry, ConditionEngine, type ConditionOperator, type CustomComponent, type CustomField, type CustomMask, type CustomValidation, type DateField, EasyForm, type EmailValidation, type ErrorEventDetail, type Field, type FieldCondition, type FieldDependencies, type FieldType, type FileDropField, type FileField, type FormColors, type FormSchema, type FormState, type FormTheme, type GroupField, INJECTION_VALIDATION_MESSAGE, type ImageGridSelectField, type LabelPosition, type MapField, type MaskConfig, MaskEngine, type MaxLengthValidation, type MaxValidation, type MinLengthValidation, type MinValidation, type NoInjectionValidation, type NumberField, type OTPField, PREDEFINED_MASKS, type PasswordField, type PatternValidation, type PredefinedMask, type QuantityField, type RadioField, type RatingField, type RequiredValidation, type RowField, SchemaParser, type SelectField, type SliderField, StateManager, type Step, type StepChangeEventDetail, type SubmitButtonConfig, type SubmitEventDetail, type SwitchField, type TemplateName, type TextField, type TextareaField, type Validation, ValidationEngine, type ValidationType, type WizardState, attributeValue, containsInjection, createInput, extendTemplate, generateId, getAvailableTemplates, getColors, getCustomComponent, getNestedValue, getPredefinedMask, getTemplate, getThemeStyles, isSafeFromInjection, isValidEmail, parseAttributeValue, registerComponent, registerComponents, sanitizeId, setNestedValue, templates };
package/dist/index.js CHANGED
@@ -63,6 +63,7 @@ var SchemaParser = class {
63
63
  "map",
64
64
  "rating",
65
65
  "slider",
66
+ "colorpicker",
66
67
  "array",
67
68
  "group",
68
69
  "row",
@@ -109,6 +110,16 @@ var SchemaParser = class {
109
110
  );
110
111
  }
111
112
  break;
113
+ case "colorpicker":
114
+ if ("defaultValue" in field && field.defaultValue != null) {
115
+ const hex = /^#[0-9A-Fa-f]{6}$/;
116
+ if (!hex.test(String(field.defaultValue))) {
117
+ throw new Error(
118
+ `Field "${field.name}" de tipo colorpicker debe tener defaultValue en formato hex (#RRGGBB)`
119
+ );
120
+ }
121
+ }
122
+ break;
112
123
  }
113
124
  }
114
125
  /**
@@ -178,6 +189,11 @@ var SchemaParser = class {
178
189
  defaults.max = 5;
179
190
  }
180
191
  break;
192
+ case "colorpicker":
193
+ if (!("defaultValue" in field) || field.defaultValue == null) {
194
+ defaults.defaultValue = "#000000";
195
+ }
196
+ break;
181
197
  }
182
198
  return { ...defaults, ...field };
183
199
  }
@@ -222,7 +238,9 @@ var defaultColors = {
222
238
  text: "#212529",
223
239
  labelColor: "#212529",
224
240
  border: "#ddd",
225
- background: "#ffffff"
241
+ background: "#ffffff",
242
+ groupBackground: "#f8f9fa",
243
+ groupTitle: "#212529"
226
244
  };
227
245
  function getColors(colors) {
228
246
  return { ...defaultColors, ...colors };
@@ -244,6 +262,8 @@ function getBaseStyles(colors) {
244
262
  --easy-form-label-color: ${colors.labelColor};
245
263
  --easy-form-border: ${colors.border};
246
264
  --easy-form-background: ${colors.background};
265
+ --easy-form-group-background: ${colors.groupBackground};
266
+ --easy-form-group-title: ${colors.groupTitle};
247
267
  }
248
268
  .easy-form-field {
249
269
  margin-bottom: 1rem;
@@ -311,6 +331,46 @@ function getBaseStyles(colors) {
311
331
  min-width: 2rem;
312
332
  font-weight: 500;
313
333
  }
334
+ .easy-form-color-wrapper {
335
+ display: flex;
336
+ align-items: center;
337
+ gap: 0.75rem;
338
+ }
339
+ .easy-form-color-wrapper input[type="color"] {
340
+ width: 2.2rem;
341
+ height: 2.2rem;
342
+ min-width: 2.2rem;
343
+ min-height: 2.2rem;
344
+ padding: 0 !important;
345
+ margin: 0;
346
+ cursor: pointer;
347
+ border: 1px solid var(--easy-form-border);
348
+ border-radius: 2px;
349
+ background: transparent;
350
+ flex-shrink: 0;
351
+ }
352
+ .easy-form-color-wrapper input[type="color"]::-webkit-color-swatch-wrapper {
353
+ padding: 0;
354
+ }
355
+ .easy-form-color-wrapper input[type="color"]::-webkit-color-swatch {
356
+ border: none;
357
+ border-radius: 1px;
358
+ }
359
+ .easy-form-color-wrapper input[type="color"]::-moz-color-swatch {
360
+ border: none;
361
+ border-radius: 1px;
362
+ }
363
+ .easy-form-color-text {
364
+ flex: 1;
365
+ min-width: 0;
366
+ color: var(--easy-form-text);
367
+ background: var(--easy-form-background);
368
+ border: 1px solid var(--easy-form-border);
369
+ border-radius: 4px;
370
+ padding: 0.5rem 0.75rem;
371
+ font-family: ui-monospace, 'Cascadia Code', 'Fira Code', 'Courier New', monospace;
372
+ font-size: 0.875rem;
373
+ }
314
374
  .easy-form-rating {
315
375
  display: inline-flex;
316
376
  gap: 0.25rem;
@@ -431,7 +491,7 @@ function getBaseStyles(colors) {
431
491
  .easy-form-submit-wrapper .easy-form-submit {
432
492
  min-width: 100px;
433
493
  }
434
- input:not([type="checkbox"]):not([type="radio"]), textarea, select {
494
+ input:not([type="checkbox"]):not([type="radio"]):not([type="color"]), textarea, select {
435
495
  width: 100%;
436
496
  padding: 0.5rem;
437
497
  font-size: 1rem;
@@ -459,6 +519,14 @@ function getBaseStyles(colors) {
459
519
  .easy-form-group {
460
520
  padding: 1rem;
461
521
  margin-bottom: 1rem;
522
+ background: var(--easy-form-group-background);
523
+ }
524
+ .easy-form-group-label {
525
+ color: var(--easy-form-group-title);
526
+ font-weight: 600;
527
+ font-size: 1rem;
528
+ margin-bottom: 0.75rem;
529
+ margin-top: 0;
462
530
  }
463
531
  .easy-form-row {
464
532
  display: flex;
@@ -1031,6 +1099,7 @@ function getPlanoStyles(_colors) {
1031
1099
  border: none;
1032
1100
  border-bottom: 1px solid var(--easy-form-border);
1033
1101
  border-radius: 0;
1102
+ background: transparent;
1034
1103
  }
1035
1104
  .easy-form-wizard-step {
1036
1105
  border: none;
@@ -1065,7 +1134,7 @@ function getTradicionalStyles(_colors) {
1065
1134
  .easy-form-group {
1066
1135
  border: 2px solid var(--easy-form-border);
1067
1136
  border-radius: 4px;
1068
- background: #f8f9fa;
1137
+ background: var(--easy-form-group-background);
1069
1138
  }
1070
1139
  .easy-form-wizard-step {
1071
1140
  border: 2px solid var(--easy-form-border);
@@ -1115,7 +1184,7 @@ function getMaterialStyles(_colors) {
1115
1184
  .easy-form-group {
1116
1185
  border: none;
1117
1186
  border-radius: 4px;
1118
- background: #f5f5f5;
1187
+ background: var(--easy-form-group-background);
1119
1188
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
1120
1189
  }
1121
1190
  .easy-form-wizard-step {
@@ -1160,7 +1229,7 @@ function getRoundedShadowStyles(_colors) {
1160
1229
  border: 1px solid var(--easy-form-border);
1161
1230
  border-radius: 16px;
1162
1231
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
1163
- background: var(--easy-form-background);
1232
+ background: var(--easy-form-group-background);
1164
1233
  }
1165
1234
  .easy-form-wizard-step {
1166
1235
  border: 1px solid var(--easy-form-border);
@@ -1214,6 +1283,7 @@ function getLinesStyles(_colors) {
1214
1283
  border-bottom: 2px solid var(--easy-form-border);
1215
1284
  border-radius: 0;
1216
1285
  padding-bottom: 1rem;
1286
+ background: transparent;
1217
1287
  }
1218
1288
  .easy-form-wizard-step {
1219
1289
  border: none;
@@ -1290,7 +1360,7 @@ function getShadcnStyles(_colors) {
1290
1360
  .easy-form-group {
1291
1361
  border: 1.5px solid #e4e4e7;
1292
1362
  border-radius: 12px;
1293
- background: linear-gradient(to bottom, var(--easy-form-background), #fafafa);
1363
+ background: var(--easy-form-group-background);
1294
1364
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
1295
1365
  padding: 1.5rem;
1296
1366
  }
@@ -1387,7 +1457,7 @@ function getChakraStyles(_colors) {
1387
1457
  .easy-form-group {
1388
1458
  border: 2px solid #e2e8f0;
1389
1459
  border-radius: 8px;
1390
- background: var(--easy-form-background);
1460
+ background: var(--easy-form-group-background);
1391
1461
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
1392
1462
  }
1393
1463
  .easy-form-wizard-step {
@@ -1468,7 +1538,7 @@ function getMantineStyles(_colors) {
1468
1538
  .easy-form-group {
1469
1539
  border: 1px solid #dee2e6;
1470
1540
  border-radius: 16px;
1471
- background: var(--easy-form-background);
1541
+ background: var(--easy-form-group-background);
1472
1542
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.8);
1473
1543
  padding: 1.5rem;
1474
1544
  }
@@ -1559,7 +1629,7 @@ function getGlassStyles(_colors) {
1559
1629
  .easy-form-group {
1560
1630
  border: 2px solid rgba(255, 255, 255, 0.4);
1561
1631
  border-radius: 20px;
1562
- background: rgba(255, 255, 255, 0.15);
1632
+ background: var(--easy-form-group-background);
1563
1633
  backdrop-filter: blur(20px) saturate(180%);
1564
1634
  -webkit-backdrop-filter: blur(20px) saturate(180%);
1565
1635
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.3);
@@ -1653,7 +1723,7 @@ function getBorderedStyles(_colors) {
1653
1723
  .easy-form-group {
1654
1724
  border: 4px solid #1a1a1a;
1655
1725
  border-radius: 0;
1656
- background: var(--easy-form-background);
1726
+ background: var(--easy-form-group-background);
1657
1727
  box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.1);
1658
1728
  padding: 2rem;
1659
1729
  }
@@ -2702,6 +2772,9 @@ var StateManager = class {
2702
2772
  }
2703
2773
  }
2704
2774
  break;
2775
+ case "colorpicker":
2776
+ values[field.name] = field.defaultValue ?? "#000000";
2777
+ break;
2705
2778
  default:
2706
2779
  values[field.name] = null;
2707
2780
  }
@@ -4940,6 +5013,66 @@ var SliderInput = class extends BaseInput {
4940
5013
  }
4941
5014
  };
4942
5015
 
5016
+ // src/components/inputs/color-input.ts
5017
+ var HEX_REGEX = /^#?([0-9A-Fa-f]{6})$/;
5018
+ function toHex(value) {
5019
+ const m = value.match(HEX_REGEX);
5020
+ if (m) return `#${m[1].toLowerCase()}`;
5021
+ if (/^[0-9A-Fa-f]{6}$/.test(value)) return `#${value.toLowerCase()}`;
5022
+ return "#000000";
5023
+ }
5024
+ var ColorInput = class extends BaseInput {
5025
+ render() {
5026
+ const colorField = this.field;
5027
+ const defaultValue = colorField.defaultValue ?? "#000000";
5028
+ const currentValue = this.value != null && typeof this.value === "string" ? toHex(this.value) : defaultValue;
5029
+ const wrapper = document.createElement("div");
5030
+ wrapper.className = "easy-form-color-wrapper";
5031
+ const colorPicker = document.createElement("input");
5032
+ colorPicker.type = "color";
5033
+ colorPicker.value = currentValue;
5034
+ colorPicker.setAttribute("value", currentValue);
5035
+ colorPicker.setAttribute("aria-label", this.field.label || "Color");
5036
+ colorPicker.id = `${this.getFieldId()}-picker`;
5037
+ if (this.field.disabled) colorPicker.setAttribute("disabled", "true");
5038
+ const textInput = document.createElement("input");
5039
+ textInput.type = "text";
5040
+ textInput.value = currentValue;
5041
+ textInput.setAttribute("aria-label", `${this.field.label || "Color"} (hex)`);
5042
+ textInput.placeholder = "#000000";
5043
+ textInput.className = "easy-form-color-text";
5044
+ this.applyCommonProps(textInput);
5045
+ const syncFromPicker = () => {
5046
+ const value = colorPicker.value || "#000000";
5047
+ const hex = toHex(value);
5048
+ textInput.value = hex;
5049
+ this.onChange(hex);
5050
+ };
5051
+ const syncFromText = () => {
5052
+ const raw = textInput.value.trim();
5053
+ const value = raw.startsWith("#") ? raw : `#${raw}`;
5054
+ if (/^#[0-9A-Fa-f]{6}$/.test(value)) {
5055
+ const hex = toHex(value);
5056
+ colorPicker.value = hex;
5057
+ this.onChange(hex);
5058
+ }
5059
+ };
5060
+ colorPicker.addEventListener("input", syncFromPicker);
5061
+ colorPicker.addEventListener("change", () => {
5062
+ syncFromPicker();
5063
+ this.onBlur();
5064
+ });
5065
+ textInput.addEventListener("input", syncFromText);
5066
+ textInput.addEventListener("blur", () => {
5067
+ syncFromText();
5068
+ this.onBlur();
5069
+ });
5070
+ wrapper.appendChild(colorPicker);
5071
+ wrapper.appendChild(textInput);
5072
+ return this.createFieldContainer(wrapper);
5073
+ }
5074
+ };
5075
+
4943
5076
  // src/components/inputs/index.ts
4944
5077
  function createInput(field, value, error, onChange, onBlur) {
4945
5078
  switch (field.type) {
@@ -4972,6 +5105,8 @@ function createInput(field, value, error, onChange, onBlur) {
4972
5105
  return new RatingInput(field, value, error, onChange, onBlur).render();
4973
5106
  case "slider":
4974
5107
  return new SliderInput(field, value, error, onChange, onBlur).render();
5108
+ case "colorpicker":
5109
+ return new ColorInput(field, value, error, onChange, onBlur).render();
4975
5110
  case "quantity":
4976
5111
  return new QuantityInput(field, value, error, onChange, onBlur).render();
4977
5112
  case "accordion-select":